-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
47 lines (42 loc) · 915 Bytes
/
utils_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
package di
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_GenericTypeOf(t *testing.T) {
type Foo struct{}
type Baz interface{}
tests := []struct {
gtype func() reflect.Type
expected string
}{
{
gtype: func() reflect.Type { return genericTypeOf[any]() },
expected: "interface {}",
},
{
gtype: func() reflect.Type { return genericTypeOf[*Foo]() },
expected: "*di.Foo",
},
{
gtype: func() reflect.Type { return genericTypeOf[Foo]() },
expected: "di.Foo",
},
{
gtype: func() reflect.Type { return genericTypeOf[Baz]() },
expected: "di.Baz",
},
{
gtype: func() reflect.Type { return genericTypeOf[[]Baz]() },
expected: "[]di.Baz",
},
}
for _, tt := range tests {
desc := tt.expected
t.Run(desc, func(t *testing.T) {
actual := tt.gtype()
assert.Equal(t, tt.expected, actual.String())
})
}
}