forked from alexkappa/exp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp_test.go
51 lines (48 loc) · 925 Bytes
/
exp_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
package exp
import "testing"
func TestExp(t *testing.T) {
for _, test := range []struct {
exp Exp
out bool
}{
{Not(True), false},
{Not(False), true},
{And(True, True), true},
{And(True, False), false},
{And(False, False), false},
{And(True, True, True), true},
{And(True, False, True), false},
{Or(True, True), true},
{Or(True, False), true},
{Or(False, False), false},
{Or(False, False, True), true},
} {
if test.exp.Eval(nil) != test.out {
t.Error("unexpected output")
}
}
}
func TestParse(t *testing.T) {
m := Map{
"foo": "124",
"bar": "x",
"b-z": "z",
}
for _, s := range []string{
`(foo == 124)`,
`(foo >= 123)`,
`(foo < 456)`,
`((foo > 200) || (bar == "x"))`,
`((foo > 100) && (bar == "x"))`,
`('b-z' == "z")`,
} {
exp, err := Parse(s)
if err != nil {
t.Fatal(err)
}
if !exp.Eval(m) {
t.Error("unexpected output")
}
t.Logf("%s", exp)
}
}