-
Notifications
You must be signed in to change notification settings - Fork 19
/
util_test.go
63 lines (58 loc) · 1.44 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
package genmai
import (
"reflect"
"testing"
)
func Test_ToInterfaceSlice(t *testing.T) {
actual := ToInterfaceSlice([]string{"1", "hoge", "foo"})
expected := []interface{}{"1", "hoge", "foo"}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %[1]q(type %[1]T), but %[2]q(type %[2]T)", expected, actual)
}
}
func TestColumnName(t *testing.T) {
for _, v := range []struct {
tableName string
columnName string
expected string
}{
{`test_table`, `*`, `"test_table".*`},
{`test_table`, `test_column`, `"test_table"."test_column"`},
{``, `test_column`, `"test_column"`},
{``, `*`, `*`},
} {
actual := ColumnName(&SQLite3Dialect{}, v.tableName, v.columnName)
expected := v.expected
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %q, but %q", expected, actual)
}
}
}
func TestIsUnexportedField(t *testing.T) {
// test for bug case less than Go1.3.
func() {
type b struct{}
type C struct {
b
}
v := reflect.TypeOf(C{}).Field(0)
actual := IsUnexportedField(v)
expected := true
if !reflect.DeepEqual(actual, expected) {
t.Errorf("IsUnexportedField(%q) => %v, want %v", v, actual, expected)
}
}()
// test for correct case.
func() {
type B struct{}
type C struct {
B
}
v := reflect.TypeOf(C{}).Field(0)
actual := IsUnexportedField(v)
expected := false
if !reflect.DeepEqual(actual, expected) {
t.Errorf("IsUnexportedField(%q) => %v, want %v", v, actual, expected)
}
}()
}