forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclauses_test.go
60 lines (49 loc) · 1.33 KB
/
clauses_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
package qb
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestSQLText(t *testing.T) {
text := SQLText("1")
assert.Equal(t, "1", text.Text)
}
func TestGetClauseFrom(t *testing.T) {
var c Clause
c = SQLText("1")
assert.Equal(t, c, GetClauseFrom(c))
c = GetClauseFrom(2)
b, ok := c.(BindClause)
assert.True(t, ok, "Should have returned a BindClause")
assert.Equal(t, 2, b.Value)
}
func TestGetListFrom(t *testing.T) {
var c Clause
c = ListClause{}
assert.Equal(t, c, GetListFrom(c))
text := SQLText("SOME SQL")
c = GetListFrom(text)
l, ok := c.(ListClause)
assert.True(t, ok, "Should have returned a ListClause")
assert.Equal(t, 1, len(l.Clauses))
assert.Equal(t, text, l.Clauses[0])
c = GetListFrom(2)
l, ok = c.(ListClause)
assert.True(t, ok, "Should have returned a ListClause")
assert.Equal(t, 1, len(l.Clauses))
assert.Equal(t, 2, l.Clauses[0].(BindClause).Value)
c = GetListFrom(2, Bind(4))
l, ok = c.(ListClause)
assert.True(t, ok, "Should have returned a ListClause")
assert.Equal(t, 2, len(l.Clauses))
assert.Equal(t, 2, l.Clauses[0].(BindClause).Value)
assert.Equal(t, 4, l.Clauses[1].(BindClause).Value)
}
func TestExists(t *testing.T) {
s := Select()
e := Exists(s)
assert.False(t, e.Not)
assert.Equal(t, s, e.Select)
ne := NotExists(s)
assert.True(t, ne.Not)
assert.Equal(t, s, ne.Select)
}