forked from wenj91/gobatis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
expr_test.go
62 lines (57 loc) · 1.41 KB
/
expr_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
package gobatis
import (
"fmt"
"testing"
)
type TestUser struct {
Name string
}
func TestExpr_eval(t *testing.T) {
params := map[string]interface{}{
"name": "wenj91",
"val": "",
"user": &TestUser{Name: "wenj91"},
"m": map[string]interface{}{"user": &TestUser{Name: "wenj91"}},
"m1": map[string]interface{}{"name": "wenj91"},
"arr": []string{"1", "2"},
"arr2": []string{},
}
expression := []string{
"1 != 1",
"1 == 1",
"name == 'wenj91'",
"name != 'wenj91'",
"user.Name1 == 'wenj91'",
"user.Name == 'wenj91'",
"user.Name != 'wenj91'",
"user.Name != nil",
"user.Name == nil",
"m.user.Name != 'wenj91'",
"m.user.Name == 'wenj91'",
"m1.name == 'wenj91'",
"m1.name != 'wenj91'",
"m.user.Name == 'wenj91' && 1 == 1",
"m.user.Name == 'wenj91' && 1 != 1",
"m.user.Name == 'wenj91' || 1 != 1",
"val != nil",
"val != ''",
"val == ''",
"val != nil && val == ''",
"val != nil and val == ''",
"arr != nil and len(arr) > 0",
"arr2 != nil and len(arr2) > 0",
}
for i, ex := range expression {
ok := eval(ex, params)
fmt.Printf("Index:%v Expr:%v >>>> Result:%v \n", i, ex, ok)
assertExpr(i, ok, ex)
}
}
func assertExpr(i int, ok bool, expr string) {
switch i {
case 0, 3, 4, 6, 8, 9, 12, 14, 17, 22: // false
assertNotTrue(ok, "Expr:"+expr+" Result:true")
case 1, 2, 5, 7, 10, 11, 13, 15, 16, 18, 19, 20, 21: // true
assertTrue(ok, "Expr:"+expr+" Result:false")
}
}