-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhere_test.go
39 lines (32 loc) · 1.12 KB
/
where_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
package sqlbuilder
import "testing"
//
// Author: 陈永佳 [email protected], [email protected]
//
func TestNewWhere(t *testing.T) {
ctx := NewContext()
sql := newWhereTest(ctx, ctx.Eq("username")).Compile()
checkSQLMatches(sql, " WHERE `username` = ?", t)
}
func TestNewWhereGroup(t *testing.T) {
ctx := NewContext()
sql := newWhereTest(ctx, Group(ctx.Eq("username").And().Eq("password"))).Compile()
checkSQLMatches(sql, " WHERE (`username` = ? AND `password` = ?)", t)
}
func TestNewWhereAnd(t *testing.T) {
ctx := NewContext()
sql := newWhereTest(ctx, ctx.Eq("username").And().Eq("password")).
Compile()
checkSQLMatches(sql, " WHERE `username` = ? AND `password` = ?", t)
}
func TestNewWhereLimit(t *testing.T) {
ctx := NewContext()
sql := newWhereTest(ctx, ctx.Eq("username").And().Eq("password")).Limit(10).
Compile()
checkSQLMatches(sql, " WHERE `username` = ? AND `password` = ? LIMIT 10", t)
}
func TestNewWhereOrderBy(t *testing.T) {
ctx := NewContext()
sql := newWhereTest(ctx, ctx.Eq("username")).OrderBy("id").ASC().Compile()
checkSQLMatches(sql, " WHERE `username` = ? ORDER BY `id` ASC", t)
}