-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqualify_test.go
More file actions
72 lines (67 loc) · 1.48 KB
/
qualify_test.go
File metadata and controls
72 lines (67 loc) · 1.48 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
package sqlparser
import (
"github.com/stretchr/testify/assert"
"github.com/viant/parsly"
"github.com/viant/sqlparser/expr"
"github.com/viant/sqlparser/node"
"testing"
)
func TestParseQualify(t *testing.T) {
var testCases = []struct {
expr string
expectEq map[string]interface{}
expectParentOp string
}{
{
expr: "col1 = ?",
expectEq: map[string]interface{}{
"col1": "?",
},
},
{
expr: "col1 in(1.0,2.0,3.0)",
expectEq: map[string]interface{}{
"col1": []interface{}{1.0, 2.0, 3.0},
},
},
}
for _, testCase := range testCases[1:] {
cursor := parsly.NewCursor("", []byte(testCase.expr), 0)
qualify := &expr.Qualify{}
err := ParseQualify(cursor, qualify)
if !assert.Nil(t, err) {
continue
}
actualEq := make(map[string]interface{})
err = qualify.X.(*expr.Binary).Walk(func(ident node.Node, values *expr.Values, operator, parentOperator string) error {
value := toValues(values)
actualEq[Stringify(ident)] = value
return nil
})
if !assert.Nil(t, err) {
continue
}
assert.EqualValues(t, testCase.expectEq, actualEq)
}
}
func toValues(values *expr.Values) interface{} {
var value interface{}
if len(values.X) == 1 {
if values.X[0].Placeholder {
value = "?"
} else {
value = values.X[0].Value
}
} else {
aSlice := make([]interface{}, len(values.X))
for i, v := range values.X {
if v.Placeholder {
aSlice[i] = "?"
} else {
aSlice[i] = v.Value
}
}
value = aSlice
}
return value
}