-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathjsonpath_comparison_test.go
More file actions
114 lines (107 loc) · 2.2 KB
/
jsonpath_comparison_test.go
File metadata and controls
114 lines (107 loc) · 2.2 KB
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
109
110
111
112
113
114
// Copyright 2015, 2021; oliver, DoltHub Authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
package jsonpath
import (
"go/token"
"go/types"
"testing"
)
// Comparison and type evaluation tests
func Test_jsonpath_types_eval(t *testing.T) {
fset := token.NewFileSet()
res, err := types.Eval(fset, nil, 0, "1 < 2")
t.Logf("err: %v, res: %v, res.Type: %v, res.Value: %v, res.IsValue: %v", err, res, res.Type, res.Value, res.IsValue())
}
var (
ifc1 interface{} = "haha"
ifc2 interface{} = "ha ha"
)
var tcase_cmp_any = []map[string]interface{}{
map[string]interface{}{
"obj1": 1,
"obj2": 1,
"op": "==",
"exp": true,
"err": nil,
},
map[string]interface{}{
"obj1": 1,
"obj2": 2,
"op": "==",
"exp": false,
"err": nil,
},
map[string]interface{}{
"obj1": 1.1,
"obj2": 2.0,
"op": "<",
"exp": true,
"err": nil,
},
map[string]interface{}{
"obj1": "1",
"obj2": "2.0",
"op": "<",
"exp": true,
"err": nil,
},
map[string]interface{}{
"obj1": "1",
"obj2": "2.0",
"op": ">",
"exp": false,
"err": nil,
},
map[string]interface{}{
"obj1": 1,
"obj2": 2,
"op": "=~",
"exp": false,
"err": "op should only be <, <=, ==, >= and >",
}, {
"obj1": ifc1,
"obj2": ifc1,
"op": "==",
"exp": true,
"err": nil,
}, {
"obj1": ifc2,
"obj2": ifc2,
"op": "==",
"exp": true,
"err": nil,
}, {
"obj1": 20,
"obj2": "100",
"op": ">",
"exp": false,
"err": nil,
},
}
func Test_jsonpath_cmp_any(t *testing.T) {
for idx, tcase := range tcase_cmp_any {
//for idx, tcase := range tcase_cmp_any[8:] {
t.Logf("idx: %v, %v %v %v, exp: %v", idx, tcase["obj1"], tcase["op"], tcase["obj2"], tcase["exp"])
res, err := cmp_any(tcase["obj1"], tcase["obj2"], tcase["op"].(string))
exp := tcase["exp"].(bool)
exp_err := tcase["err"]
if exp_err != nil {
if err == nil {
t.Errorf("idx: %d error not raised: %v(exp)", idx, exp_err)
break
}
} else {
if err != nil {
t.Errorf("idx: %v, error: %v", idx, err)
break
}
}
if res != exp {
t.Errorf("idx: %v, %v(got) != %v(exp)", idx, res, exp)
break
}
}
}