-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathutil_test.go
94 lines (90 loc) · 1.34 KB
/
util_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
package dbr
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSnakeCase(t *testing.T) {
for _, test := range []struct {
in string
want string
}{
{
in: "",
want: "",
},
{
in: "IsDigit",
want: "is_digit",
},
{
in: "Is",
want: "is",
},
{
in: "IsID",
want: "is_id",
},
{
in: "IsSQL",
want: "is_sql",
},
{
in: "LongSQL",
want: "long_sql",
},
{
in: "Float64Val",
want: "float64_val",
},
{
in: "XMLName",
want: "xml_name",
},
} {
assert.Equal(t, test.want, camelCaseToSnakeCase(test.in))
}
}
func TestStructMap(t *testing.T) {
for _, test := range []struct {
in interface{}
expected map[string][]int
}{
{
in: struct {
CreatedAt time.Time
}{},
expected: map[string][]int{"created_at": {0}},
},
{
in: struct {
intVal int
}{},
expected: map[string][]int{},
},
{
in: struct {
IntVal int `db:"test"`
}{},
expected: map[string][]int{"test": {0}},
},
{
in: struct {
IntVal int `db:"-"`
}{},
expected: map[string][]int{},
},
{
in: struct {
Test1 struct {
Test2 int
}
}{},
expected: map[string][]int{"test1": {0}, "test2": {0, 0}},
},
} {
m := structMap(reflect.ValueOf(test.in).Type())
assert.Equal(t, test.expected, m)
}
}