-
Notifications
You must be signed in to change notification settings - Fork 28
/
field_test.go
72 lines (60 loc) · 1.33 KB
/
field_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
66
67
68
69
70
71
72
package sqlingo
import (
"errors"
"testing"
)
type dummyTable struct {
}
func (d dummyTable) GetName() string {
panic("should not be here")
}
func (d dummyTable) GetSQL(scope scope) string {
panic("should not be here")
}
func (d dummyTable) GetFieldByName(name string) Field {
panic("should not be here")
}
func (d dummyTable) GetFields() []Field {
panic("implement me")
}
func (d dummyTable) GetFieldsSQL() string {
return "<fields sql>"
}
func (d dummyTable) GetFullFieldsSQL() string {
return "<full fields sql>"
}
func TestField(t *testing.T) {
t1 := NewTable("t1")
assertValue(t, NewNumberField(t1, "f1").Equals(1), "`t1`.`f1` = 1")
assertValue(t, NewBooleanField(t1, "f1").Equals(true), "`t1`.`f1` = 1")
assertValue(t, NewStringField(t1, "f1").Equals("x"), "`t1`.`f1` = 'x'")
sql, _ := fieldList{}.GetSQL(scope{
Tables: []Table{
&dummyTable{},
},
})
if sql != "<fields sql>" {
t.Error(sql)
}
sql, _ = fieldList{}.GetSQL(scope{
Tables: []Table{
&dummyTable{},
&dummyTable{},
},
})
if sql != "<full fields sql>, <full fields sql>" {
t.Error(sql)
}
if _, err := (fieldList{
expression{builder: func(scope scope) (string, error) {
return "", errors.New("error")
}},
}.GetSQL(scope{
Tables: []Table{
&dummyTable{},
&dummyTable{},
},
})); err == nil {
t.Error("should get error here")
}
}