-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression_test.go
62 lines (47 loc) · 1.62 KB
/
expression_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 sqlb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEq(t *testing.T) {
e := Eq{"foo", "bar"}
sql, args, _ := e.ToExpr()
assert.Equal(t, "foo = ?", sql, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}
func TestNotEq(t *testing.T) {
e := NotEq{"foo", "bar"}
sql, args, _ := e.ToExpr()
assert.Equal(t, "foo <> ?", sql, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}
func TestIn(t *testing.T) {
e := In{"foo", []interface{}{"bar"}}
sql, args, _ := e.ToExpr()
assert.Equal(t, "foo IN (?)", sql, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}
func TestAnd(t *testing.T) {
e := And{Eq{"foo", "bar"}}
sql, args, _ := e.ToExpr()
assert.Equal(t, "foo = ?", sql, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}
func TestLike(t *testing.T) {
e := And{Like{"foo", "bar"}}
sql, args, _ := e.ToExpr()
assert.Equal(t, "foo LIKE ?", sql, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}
func TestEmptyExpr(t *testing.T) {
e := And{}
sql, args, _ := e.ToExpr()
assert.Equal(t, "", sql, "they should be equal")
assert.Equal(t, 0, len(args), "they should be equal")
}
func TestNestedExpr(t *testing.T) {
e := Nested{"id", InOperator, Select("id").From("table").Where(Eq{"foo", "bar"})}
expr, args, _ := e.ToExpr()
assert.Equal(t, "id IN (SELECT id FROM table WHERE foo = ?)", expr, "they should be equal")
assert.Equal(t, []interface{}{"bar"}, args, "they should be equal")
}