-
Notifications
You must be signed in to change notification settings - Fork 40
/
unit_test.go
65 lines (54 loc) · 1.52 KB
/
unit_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
63
64
65
package main
import (
"github.com/mijia/modelq/gmq"
"log"
"testing"
)
func TestOptions(t *testing.T) {
var o gmq.OptionInt
o = gmq.SomeInt(5)
if n, err := o.Get(); err != nil || n != 5 {
t.Errorf("Option get is not working, got err or wrong value, %s, %d", err, n)
}
if !o.IsDefined() {
t.Errorf("Option isDefined is not working, expectd defined")
}
o = gmq.NoneInt()
if n, err := o.Get(); err == nil {
t.Errorf("Option get is not working, should get error for NoneInt, %s, %d", err, n)
}
if o.IsDefined() {
t.Errorf("Option isDefined is not working, expectd not defined")
}
}
func TestCapitalCase(t *testing.T) {
cases := [][]string{
[]string{"cp_user_124_jiu", "CpUser124Jiu"},
[]string{"Cp_u___test", "CpUTest"},
[]string{"hello23World", "Hello23World"},
[]string{"CP_test_USer", "CpTestUser"},
[]string{"USER", "User"},
}
for _, cs := range cases {
target := toCapitalCase(cs[0])
if target != cs[1] {
t.Errorf("src %s, expected %s, got %s", cs[0], cs[1], target)
}
}
}
func TestGmqFilters(t *testing.T) {
left := gmq.UnitFilter("id", "=", 1)
log.Println(left.SqlString("User"), left.Params())
right := gmq.UnitFilter("name", "LIKE", "hello%")
log.Println(right.SqlString("User"), right.Params())
and := left.And(right)
log.Println(and.SqlString("User"), and.Params())
in := gmq.InFilter("id", []interface{}{10, 20, 30})
log.Println(in.SqlString("User"), in.Params())
or := and.Or(in)
log.Println(or.SqlString("User"), or.Params())
}
func init() {
gmq.Debug = true
}
var _ = log.Println