-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_helpers_test.go
57 lines (39 loc) · 1.18 KB
/
build_helpers_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
package qb
import (
"testing"
"git.fuyu.moe/Fuyu/assert"
)
func TestMakeFieldWithField(t *testing.T) {
assert := assert.New(t)
f := TableField{Name: `f1`}
assert.Eq(f, MakeField(f))
}
func TestMakeFieldWithValue(t *testing.T) {
assert := assert.New(t)
assert.Eq(Value(`a`), MakeField(`a`))
}
func TestConcatQueryString(t *testing.T) {
assert := assert.New(t)
output := ConcatQuery(nil, `a`, `, `, `b`)
assert.Eq(`a, b`, output)
}
func TestConcatQueryField(t *testing.T) {
assert := assert.New(t)
f := TableField{Name: `f`}
output := ConcatQuery(NewContext(nil, NoAlias()), f, `, `, f)
assert.Eq(`f, f`, output)
}
func TestConcatQuerySubquery(t *testing.T) {
assert := assert.New(t)
sq := &SelectBuilder{source: &Table{Name: `tbl`}, fields: []Field{TableField{Name: `f1`}}}
NEWLINE, INDENT = ``, ``
output := ConcatQuery(NewContext(nil, NoAlias()), sq, `, `, sq)
NEWLINE, INDENT = "\n", "\t"
assert.Eq("(SELECT f1FROM tbl AS t), (SELECT f1FROM tbl AS t)", output)
}
func TestJoinQuery(t *testing.T) {
assert := assert.New(t)
f := TableField{Name: `f1`}
output := JoinQuery(NewContext(nil, NoAlias()), `, `, []interface{}{f, f, f})
assert.Eq(`f1, f1, f1`, output)
}