-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringify_test.go
45 lines (43 loc) · 1.35 KB
/
stringify_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
package gostructstringify
import (
"math"
"testing"
)
type testStruct struct {
A string
B int
}
type SuperStruct struct {
E string
F *testStruct
}
type SuperStructList struct {
G string
Lst []*testStruct
}
type Unit string
type MiscFloat float64
func Test_generateStructInstanceCode(t *testing.T) {
type args struct {
instance interface{}
}
tests := []struct {
name string
args args
want string
}{
{"valid", args{&testStruct{ A: "a", B: 1}}, "&gostructstringify.testStruct{A: \"a\", B: 1}"},
{"valid sub", args{&SuperStruct{ E: "asdf", F:&testStruct{A: "a", B: 1}}}, "&gostructstringify.SuperStruct{E: \"asdf\", F: &gostructstringify.testStruct{A: \"a\", B: 1}}"},
{"valid sub", args{&SuperStructList{ G: "asdf", Lst: []*testStruct{{A: "a", B: 1}, {A: "a", B: 1}}}}, "&gostructstringify.SuperStructList{G: \"asdf\", Lst: []*gostructstringify.testStruct{&gostructstringify.testStruct{A: \"a\", B: 1}, &gostructstringify.testStruct{A: \"a\", B: 1}}}"},
{"valid", args{Unit("asdf")}, "gostructstringify.Unit(\"asdf\")"},
{"valid", args{MiscFloat(1)}, "gostructstringify.MiscFloat(1)"},
{"valid", args{math.NaN()}, "math.NaN()"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StructStringify(tt.args.instance); got != tt.want {
t.Errorf("generateStructInstanceCode() = %v, want %v", got, tt.want)
}
})
}
}