forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
condition_test.go
49 lines (43 loc) · 1.38 KB
/
condition_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
package helper
import (
"testing"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
func TestCondition(t *testing.T) {
data := []byte(`{ "用户不存在": "张三", "=": "李四" }`)
cond := Condition{}
err := jsoniter.Unmarshal(data, &cond)
assert.Nil(t, err)
assert.Equal(t, "张三", cond.Left)
assert.Equal(t, "李四", cond.Right)
assert.Equal(t, "=", cond.OP)
assert.Equal(t, "用户不存在", cond.Comment)
assert.Equal(t, false, cond.OR)
assert.False(t, cond.Exec())
data = []byte(`{ "用户不存在":"张三", "is":"null" }`)
cond = Condition{}
err = jsoniter.Unmarshal(data, &cond)
assert.Nil(t, err)
assert.Equal(t, "张三", cond.Left)
assert.Equal(t, "null", cond.Right)
assert.Equal(t, "is", cond.OP)
assert.Equal(t, "用户不存在", cond.Comment)
assert.Equal(t, false, cond.OR)
assert.False(t, cond.Exec())
data = []byte(`{ "left":"李四", "right":"李四", "op":"=", "or":true }`)
cond = Condition{}
err = jsoniter.Unmarshal(data, &cond)
assert.Nil(t, err)
assert.Equal(t, "李四", cond.Left)
assert.Equal(t, "李四", cond.Right)
assert.Equal(t, "=", cond.OP)
assert.Equal(t, true, cond.OR)
assert.True(t, cond.Exec())
data, err = jsoniter.Marshal(cond)
assert.Nil(t, err)
str := string(data)
assert.Contains(t, str, `"=":"李四"`)
assert.Contains(t, str, `"or":true`)
assert.Contains(t, str, `"left":"李四"`)
}