forked from worldline-go/struct2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptr2_test.go
74 lines (72 loc) · 1.23 KB
/
ptr2_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
package struct2
import (
"reflect"
"testing"
)
func TestPtr2Concrete(t *testing.T) {
type args struct {
val interface{}
}
tests := []struct {
name string
args args
want interface{}
}{
{
name: "non pointer test",
args: args{
val: "non pointer",
},
want: "non pointer",
},
{
name: "pointer test",
args: args{
val: str2Ptr("pointer"),
},
want: "pointer",
},
{
name: "struct test",
args: args{
val: struct{ name string }{name: "struct"},
},
want: struct{ name string }{name: "struct"},
},
{
name: "pointer struct test",
args: args{
val: &struct{ name string }{name: "struct"},
},
want: struct{ name string }{name: "struct"},
},
{
name: "pointer struct test with nil",
args: args{
val: (*struct{ name string })(nil),
},
want: struct{ name string }{},
},
{
name: "nil string",
args: args{
val: (*string)(nil),
},
want: "",
},
{
name: "nil int",
args: args{
val: (*int)(nil),
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Ptr2Concrete(tt.args.val); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Ptr2Concrete() = %v, want %v", got, tt.want)
}
})
}
}