-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathattrs_test.go
81 lines (72 loc) · 1.64 KB
/
attrs_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
package attrs
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_Attr_GoType(t *testing.T) {
tt := []struct {
ct string
gt string
}{
{"timestamp", "time.Time"},
{"datetime", "time.Time"},
{"date", "time.Time"},
{"time", "time.Time"},
{"text", "string"},
{"Text", "string"},
{"nulls.text", "nulls.String"},
{"nulls.Text", "nulls.String"},
{"uuid", "uuid.UUID"},
{"json", "slices.Map"},
{"jsonb", "slices.Map"},
{"[]string", "slices.String"},
{"[]int", "slices.Int"},
{"slices.float", "slices.Float"},
{"[]float", "slices.Float"},
{"[]float32", "slices.Float"},
{"[]float64", "slices.Float"},
{"decimal", "float64"},
{"float", "float64"},
{"[]byte", "[]byte"},
{"blob", "[]byte"},
}
for _, test := range tt {
t.Run(test.ct+"/"+test.gt, func(st *testing.T) {
r := require.New(st)
a := Attr{commonType: test.ct}
r.Equal(test.gt, a.GoType())
})
}
}
func Test_Attr_CommonType(t *testing.T) {
tt := []struct {
pt string
ct string
}{
{"timestamp", "timestamp"},
{"datetime", "timestamp"},
{"date", "date"},
{"time", "timestamp"},
{"text", "text"},
{"Text", "text"},
{"nulls.text", "text"},
{"nulls.Text", "text"},
{"uuid", "uuid"},
{"slices.Map", "json"},
{"slices.String", "[]string"},
{"slices.Int", "[]int"},
{"slices.float", "[]float"},
{"slices.Float", "[]float"},
{"[]float64", "[]float"},
{"float64", "decimal"},
{"float", "decimal"},
{"[]byte", "[]byte"},
}
for _, test := range tt {
t.Run(test.pt+"/"+test.ct, func(st *testing.T) {
r := require.New(st)
a := Attr{commonType: test.pt}
r.Equal(test.ct, a.CommonType())
})
}
}