-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcolumn_test.go
106 lines (85 loc) · 1.96 KB
/
column_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ddlmaker
import (
"reflect"
"testing"
"github.com/kayac/ddl-maker/dialect/mysql"
)
func TestSize(t *testing.T) {
c := column{
name: "dummy",
}
if size, err := c.size(); size != 0 || err != nil {
t.Fatal("parse size error")
}
c = column{
name: "dummy",
tag: "size=10",
}
if size, err := c.size(); size != 10 || err != nil {
t.Fatal("parse size error")
}
}
func TestSpecs(t *testing.T) {
c := column{
name: "name",
tag: "size=10,pk,default=jon",
}
specs := map[string]string{
"size": "10",
"pk": "",
"default": "jon",
}
if !reflect.DeepEqual(c.specs(), specs) {
t.Fatalf("parse tag error. result: %q", c.specs())
}
}
func TestAttribute(t *testing.T) {
c := column{dialect: mysql.MySQL{}}
if c.attribute() != "NOT NULL" {
t.Fatalf("error column attribute. result:%s", c.attribute())
}
c.tag = "null"
if c.attribute() != "NULL" {
t.Fatalf("error column attribute. result:%s", c.attribute())
}
c.tag = "default=0"
if c.attribute() != "NOT NULL DEFAULT 0" {
t.Fatalf("error column attribute. result:%s", c.attribute())
}
c.tag = "auto"
if c.attribute() != "NOT NULL AUTO_INCREMENT" {
t.Fatalf("error column attribute. result:%s", c.attribute())
}
}
func TestToSQL(t *testing.T) {
c := column{
typeName: "int64",
name: "id",
dialect: mysql.MySQL{},
}
if c.ToSQL() != "`id` BIGINT NOT NULL" {
t.Fatalf("error ToSQL. result: %s", c.ToSQL())
}
c.typeName = "uint64"
if c.ToSQL() != "`id` BIGINT unsigned NOT NULL" {
t.Fatalf("error ToSQL. result: %s", c.ToSQL())
}
c = column{
typeName: "string",
name: "description",
tag: "size=20,null",
dialect: mysql.MySQL{},
}
if c.ToSQL() != "`description` VARCHAR(20) NULL" {
t.Fatalf("error ToSQL. result: %s", c.ToSQL())
}
c = column{
typeName: "string",
name: "comment",
tag: "null,type=text",
dialect: mysql.MySQL{},
}
if c.ToSQL() != "`comment` TEXT NULL" {
t.Fatalf("error ToSQL. result: %s", c.ToSQL())
}
}