-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
ExpressionEngineProxy_test.go
108 lines (96 loc) · 2.64 KB
/
ExpressionEngineProxy_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
package GoMybatis
import (
"github.com/zhuxiujia/GoMybatis/engines"
"github.com/zhuxiujia/GoMybatis/example"
"fmt"
"testing"
)
func TestExpressionEngineProxy_Eval(t *testing.T) {
var engine = ExpressionEngineProxy{}.New(&engines.ExpressionEngineGoExpress{}, false)
var lexer, err = engine.Lexer("foo")
if err != nil {
t.Fatal(err)
}
var arg = make(map[string]interface{})
arg["foo"] = "Bar"
result, err := engine.Eval(lexer, arg, 0)
if err != nil {
t.Fatal(err)
}
if result.(string) != "Bar" {
t.Fatal("result != 'Bar'")
}
fmt.Println(result)
}
func TestExpressionEngineProxy_Lexer(t *testing.T) {
var engine = ExpressionEngineProxy{}.New(&engines.ExpressionEngineGoExpress{}, false)
var _, err = engine.Lexer("foo")
if err != nil {
t.Fatal(err)
}
}
func BenchmarkExpressionEngineProxy_Eval(b *testing.B) {
b.StopTimer()
var activity = example.Activity{
Id: "1",
DeleteFlag: 1,
}
var engine = ExpressionEngineProxy{}.New(&engines.ExpressionEngineGoExpress{}, false)
var evaluateParameters = make(map[string]interface{})
evaluateParameters["activity"] = &activity
b.StartTimer()
for i := 0; i < b.N; i++ {
var expression = "activity.DeleteFlag == 1 and activity.DeleteFlag != 0 "
evalExpression, err := engine.Lexer(expression)
if err != nil {
b.Fatal(err)
}
result, err := engine.Eval(evalExpression, evaluateParameters, 0)
if err != nil {
b.Fatal(err)
}
if result.(bool) {
}
}
}
func BenchmarkExpressionEngineProxy_Eval_each(b *testing.B) {
b.StopTimer()
var engine = ExpressionEngineProxy{}.New(&engines.ExpressionEngineGoExpress{}, true)
var evaluateParameters = make(map[string]interface{})
var name = "dsafas"
evaluateParameters["activity"] = &name
b.StartTimer()
for i := 0; i < b.N; i++ {
for run := 0; run < 8; run++ {
var expression = "activity"
evalExpression, err := engine.Lexer(expression)
if err != nil {
b.Fatal(err)
}
_, err = engine.Eval(evalExpression, evaluateParameters, 0)
if err != nil {
b.Fatal(err)
}
}
}
}
func BenchmarkExpressionEngineProxy_LexerAndEval(b *testing.B) {
b.StopTimer()
var engine = ExpressionEngineProxy{}.New(&engines.ExpressionEngineGoExpress{}, true)
var evaluateParameters = make(map[string]interface{})
var name = "dsafas"
evaluateParameters["activity"] = name
//evaluateParameters["func_activity != nil"] = func(arg map[string]interface{}) interface{} {
// return arg["activity"] != nil
//}
b.StartTimer()
for i := 0; i < b.N; i++ {
for run := 0; run < 8; run++ {
var expression = "activity != nil"
_, err := engine.LexerAndEval(expression, evaluateParameters)
if err != nil {
b.Fatal(err)
}
}
}
}