-
Notifications
You must be signed in to change notification settings - Fork 664
/
case_test.go
62 lines (52 loc) · 1.58 KB
/
case_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 helper
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
)
func TestCase(t *testing.T) {
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
return process.Args
})
case1 := CaseParam{
When: []Condition{
{Left: "张三", OP: "=", Right: "李四", Compute: Computes["="]},
{OR: true, Left: "李四", OP: "=", Right: "李四", Compute: Computes["="]},
},
Name: "打印信息",
Process: "xiang.unit.Return",
Args: []interface{}{"world"},
}
case2 := CaseParam{
When: []Condition{
{Left: "张三", OP: "=", Right: "张三", Compute: Computes["="]},
},
Name: "打印信息",
Process: "xiang.unit.Return",
Args: []interface{}{"foo"},
}
v := Case(case1, case2).([]interface{})
assert.Equal(t, "world", v[0])
}
func TestProcessCase(t *testing.T) {
process.Register("xiang.unit.return", func(process *process.Process) interface{} {
return process.Args
})
args := []interface{}{
map[string]interface{}{
"when": []map[string]interface{}{{"用户": "张三", "=": "李四"}, {"or": true, "用户": "李四", "=": "李四"}},
"name": "打印信息",
"process": "xiang.unit.Return",
"args": []interface{}{"world"},
},
map[string]interface{}{
"when": []map[string]interface{}{{"用户": "张三", "=": "张三"}},
"name": "打印信息",
"process": "xiang.unit.Return",
"args": []interface{}{"foo"},
},
}
process := process.New("xiang.helper.Case", args...)
res := process.Run().([]interface{})
assert.Equal(t, "world", res[0])
}