@@ -7,17 +7,52 @@ import (
7
7
"testing"
8
8
)
9
9
10
- var aAndB = `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "rule ":"less", "value ":1}}, { "field": "b", "condition":{ "rule ":"greater", "value ":"abc" }}]}`
11
- var aOrB = `{ "glue":"or", "rules":[{ "field": "a", "condition":{ "rule ":"less", "value ":1}}, { "field": "b", "condition":{ "rule ":"greater", "value ":"abc" }}]}`
12
- var cOrC = `{ "glue":"or", "rules":[{ "field": "a", "condition":{ "rule ":"is null" }}, { "field": "b", "condition":{ "rule ":"range100", "value ":500 }}]}`
10
+ var aAndB = `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type ":"less", "filter ":1}}, { "field": "b", "condition":{ "type ":"greater", "filter ":"abc" }}]}`
11
+ var aOrB = `{ "glue":"or", "rules":[{ "field": "a", "condition":{ "type ":"less", "filter ":1}}, { "field": "b", "condition":{ "type ":"greater", "filter ":"abc" }}]}`
12
+ var cOrC = `{ "glue":"or", "rules":[{ "field": "a", "condition":{ "type ":"is null" }}, { "field": "b", "condition":{ "type ":"range100", "filter ":500 }}]}`
13
13
14
14
var cases = [][]string {
15
15
[]string {`{}` , "" , "" },
16
16
[]string {
17
- `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "rule ":"equal", "value ":1 }}]}` ,
17
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type ":"equal", "filter ":1 }}]}` ,
18
18
"a = ?" ,
19
19
"1" ,
20
20
},
21
+ []string {
22
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notEqual", "filter":1 }}]}` ,
23
+ "a <> ?" ,
24
+ "1" ,
25
+ },
26
+ []string {
27
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"less", "filter":1 }}]}` ,
28
+ "a < ?" ,
29
+ "1" ,
30
+ },
31
+ []string {
32
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"lessOrEqual", "filter":1 }}]}` ,
33
+ "a <= ?" ,
34
+ "1" ,
35
+ },
36
+ []string {
37
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"greater", "filter":1 }}]}` ,
38
+ "a > ?" ,
39
+ "1" ,
40
+ },
41
+ []string {
42
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"greaterOrEqual", "filter":1 }}]}` ,
43
+ "a >= ?" ,
44
+ "1" ,
45
+ },
46
+ []string {
47
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"contains", "filter":1 }}]}` ,
48
+ "INSTR(a, ?) > 0" ,
49
+ "1" ,
50
+ },
51
+ []string {
52
+ `{ "glue":"and", "rules":[{ "field": "a", "condition":{ "type":"notContains", "filter":1 }}]}` ,
53
+ "INSTR(a, ?) < 0" ,
54
+ "1" ,
55
+ },
21
56
[]string {
22
57
aAndB ,
23
58
"( a < ? AND b > ? )" ,
@@ -29,7 +64,7 @@ var cases = [][]string{
29
64
"1,abc" ,
30
65
},
31
66
[]string {
32
- `{ "glue":"AND", "rules":[` + aAndB + `,` + aOrB + `,{ "field":"c", "condition": { "rule ":"equal", "value ":3 } }]}` ,
67
+ `{ "glue":"AND", "rules":[` + aAndB + `,` + aOrB + `,{ "field":"c", "condition": { "type ":"equal", "filter ":3 } }]}` ,
33
68
"( ( a < ? AND b > ? ) AND ( a < ? OR b > ? ) AND c = ? )" ,
34
69
"1,abc,1,abc,3" ,
35
70
},
@@ -45,6 +80,7 @@ var cases = [][]string{
45
80
},
46
81
}
47
82
83
+
48
84
func anyToStringArray (some []interface {}) (string , error ) {
49
85
out := make ([]string , 0 , len (some ))
50
86
for _ , x := range some {
0 commit comments