-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
81 lines (77 loc) · 1.59 KB
/
parser_test.go
File metadata and controls
81 lines (77 loc) · 1.59 KB
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
package boolal_test
import (
"testing"
ba "github.com/lesomnus/boolal"
"github.com/stretchr/testify/require"
)
func TestParse(t *testing.T) {
tcs := []struct {
desc string
input string
expected *ba.Expr
}{
{
desc: "No op",
input: "x",
expected: &ba.Expr{Lhs: ba.Var("x")},
},
{
desc: "Negation",
input: "!x",
expected: &ba.Expr{Lhs: ba.Not("x")},
},
{
desc: "Conjunction",
input: "x & y",
expected: ba.And("x", "y"),
},
{
desc: "Disjunction",
input: "x | y",
expected: ba.Or("x", "y"),
},
{
desc: "Conjunctions",
input: "x & y & z",
expected: ba.And("x", "y", "z"),
},
{
desc: "Disjunctions",
input: "x | y | z",
expected: ba.Or("x", "y", "z"),
},
{
desc: "Mixed junctions",
input: "x & !y | z",
expected: ba.And("x", ba.Not("y")).Or("z"),
},
{
desc: "sub-expression on right side",
input: "x & (y | z)",
expected: ba.And("x", ba.Or("y", "z")),
},
{
desc: "sub-expression on left side",
input: "(x & y) | z",
expected: ba.Or(ba.And("x", "y"), "z"),
},
{
desc: "nested sub-expressions",
input: "x & (y | (z & a))",
expected: ba.And("x", ba.Or("y", ba.And("z", "a"))),
},
{
desc: "sub-expressions with unary op",
input: "x & !(y | z)",
expected: ba.And("x", ba.Not(ba.Or("y", "z"))),
},
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
require := require.New(t)
al, err := ba.ParseString(tc.input)
require.NoError(err)
require.Equal(tc.expected, al)
})
}
}