forked from viant/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileset_info_test.go
77 lines (56 loc) · 2.01 KB
/
fileset_info_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
package toolbox_test
import (
"github.com/stretchr/testify/assert"
"github.com/viant/toolbox"
"testing"
)
func TestNewFileSetInfoInfo(t *testing.T) {
fileSetInfo, err := toolbox.NewFileSetInfo("./fileset_info_test/")
if err != nil {
panic(err)
}
assert.Equal(t, 2, len(fileSetInfo.FilesInfo()))
fileInfo := fileSetInfo.FileInfo("user_test.go")
assert.NotNil(t, fileInfo)
assert.False(t, fileInfo.HasStructInfo("F"))
assert.True(t, fileInfo.HasStructInfo("User"))
assert.Equal(t, 2, len(fileInfo.Structs()))
address := fileSetInfo.Struct("Address")
assert.NotNil(t, address)
address2 := fileSetInfo.Struct("Address2")
assert.Nil(t, address2)
userInfo := fileInfo.Struct("User")
assert.NotNil(t, userInfo)
assert.True(t, userInfo.HasField("ID"))
assert.True(t, userInfo.HasField("Name"))
assert.False(t, userInfo.HasField("FF"))
assert.Equal(t, 8, len(userInfo.Fields()))
idInfo := userInfo.Field("ID")
assert.True(t, idInfo.IsPointer)
assert.Equal(t, "int", idInfo.TypeName)
assert.Equal(t, true, idInfo.IsPointer)
dobInfo := userInfo.Field("DateOfBirth")
assert.True(t, dobInfo.IsStruct)
assert.Equal(t, "time.Time", dobInfo.TypeName)
assert.Equal(t, "time", dobInfo.TypePackage)
assert.Equal(t, "`foo=\"bar\"`", dobInfo.Tag)
addressPointer := userInfo.Field("AddressPointer")
assert.NotNil(t, addressPointer)
assert.Equal(t, true, addressPointer.IsStruct)
assert.Equal(t, "Address", addressPointer.TypeName)
cInfo := userInfo.Field("C")
assert.True(t, cInfo.IsChannel)
mInfo := userInfo.Field("M")
assert.True(t, mInfo.IsMap)
assert.Equal(t, "string", mInfo.KeyTypeName)
assert.Equal(t, "[]string", mInfo.ValueTypeName)
intsInfo := userInfo.Field("Ints")
assert.True(t, intsInfo.IsSlice)
assert.Equal(t, "my comments", userInfo.Comment)
assert.False(t, userInfo.HasReceiver("Abc"))
assert.Equal(t, 3, len(userInfo.Receivers()))
assert.True(t, userInfo.HasReceiver("Test"))
assert.True(t, userInfo.HasReceiver("Test2"))
receiver := userInfo.Receiver("Test")
assert.NotNil(t, receiver)
}