-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_errors_test.go
111 lines (90 loc) · 4.67 KB
/
parser_errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package parser
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Case without parentheses
func Test_error_case1(t *testing.T) {
assert.False(t, testExpression(""))
assert.True(t, testExpression("alice and bob"))
assert.True(t, testExpression("not alice and bob"))
assert.True(t, testExpression("alice and not bob"))
assert.True(t, testExpression("not alice and not bob"))
assert.True(t, testExpression("alice or bob"))
assert.True(t, testExpression("not alice or bob"))
assert.True(t, testExpression("alice or not bob"))
assert.True(t, testExpression("not alice or not bob"))
assert.True(t, testExpression("alice"))
assert.True(t, testExpression("not alice"))
assert.False(t, testExpression("alice and and bob"))
assert.False(t, testExpression("alice or or bob"))
assert.False(t, testExpression("alice and or bob"))
assert.False(t, testExpression("alice or and bob"))
assert.False(t, testExpression("not alice and and bob"))
assert.False(t, testExpression("not alice or or bob"))
assert.False(t, testExpression("not alice and or bob"))
assert.False(t, testExpression("not alice or and bob"))
assert.False(t, testExpression("alice and and not bob"))
assert.False(t, testExpression("alice or or not bob"))
assert.False(t, testExpression("alice and or not bob"))
assert.False(t, testExpression("alice or and not bob"))
assert.False(t, testExpression("not alice and and not bob"))
assert.False(t, testExpression("not alice or or not bob"))
assert.False(t, testExpression("not alice and or not bob"))
assert.False(t, testExpression("not alice or and not bob"))
assert.False(t, testExpression("and alice and bob"))
assert.False(t, testExpression("or alice or bob"))
assert.False(t, testExpression("and alice or bob"))
assert.False(t, testExpression("or alice and bob"))
assert.False(t, testExpression("alice and bob and"))
assert.False(t, testExpression("alice or bob or"))
assert.False(t, testExpression("alice and bob or"))
assert.False(t, testExpression("alice or bob and"))
assert.False(t, testExpression("alice not"))
assert.False(t, testExpression("alice not bob"))
}
// Case with parentheses
func Test_error_case2(t *testing.T) {
assert.True(t, testExpression("(alice and bob)"))
assert.True(t, testExpression("(alice and bob) and (carol and dan)"))
assert.True(t, testExpression("(alice and bob) and (carol and dan) and (elen and gleen)"))
assert.True(t, testExpression("not (alice and bob) and (carol and dan) and (elen and gleen)"))
assert.True(t, testExpression("not (alice and bob) and not (carol and dan) and (elen and gleen)"))
assert.True(t, testExpression("not (alice and bob) and not (carol and dan) and not (elen and gleen)"))
assert.True(t, testExpression("(alice or bob)"))
assert.True(t, testExpression("(alice or bob) or (carol or dan)"))
assert.True(t, testExpression("(alice or bob) or (carol or dan) or (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) or (carol or dan) or (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) or not (carol or dan) or (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) or not (carol or dan) or not (elen or gleen)"))
assert.True(t, testExpression("(alice or bob)"))
assert.True(t, testExpression("(alice or bob) and (carol or dan)"))
assert.True(t, testExpression("(alice or bob) and (carol or dan) and (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) and (carol or dan) and (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) and not (carol or dan) and (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) and (not (carol or dan)) and not (elen or gleen)"))
assert.True(t, testExpression("not (alice or bob) and not (carol or dan) and not (elen or gleen)"))
assert.True(t, testExpression("((not (alice or bob)) and (not (carol or dan)))"))
assert.True(t, testExpression("(alice or bob) and (not ((carol or dan) and (elen or gleen)))"))
assert.True(t, testExpression("((alice or bob) and ((carol or dan) and (elen or gleen)))"))
assert.True(t, testExpression("((alice or bob) and (carol or dan)) and (elen or gleen) and ((not ((alice or bob) and (carol or dan)) and (elen or gleen)))"))
}
func Test_error_case3(t *testing.T) {
assert.False(t, testExpression("alice and "))
assert.False(t, testExpression("alice and or bob "))
assert.False(t, testExpression("(alice and bob))"))
assert.False(t, testExpression("((alice and bob)"))
assert.False(t, testExpression("()"))
assert.False(t, testExpression("(())"))
}
func Test_error_case4(t *testing.T) {
p := parser2{}
{
_, err := p.Go("str")
assert.Equal(t, ErrorNotDefinedStr, err)
}
{
_, err := p.Go("str or str")
assert.Equal(t, ErrorNotDefinedStrORStr, err)
}
}