-
Notifications
You must be signed in to change notification settings - Fork 1
/
kind_interface_test.go
60 lines (51 loc) · 1.12 KB
/
kind_interface_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
package dapper_test
import "testing"
func TestPrinter_Interface(t *testing.T) {
type interfaces struct {
Iface any
Force bool // prevent rendering of the zero-value marker
}
type iface any
// Note that capturing a reflect.Value of a nil interface does NOT produces
// a value with a "kind" of reflect.Invalid, NOT reflect.Interface.
test(t, "nil any interface", any(nil), "any(nil)")
test(t, "nil named interface", iface(nil), "any(nil)") // interface information is shed when passed to Printer.Write().
test(
t,
"nil interface in named struct",
interfaces{Force: true},
"github.com/dogmatiq/dapper_test.interfaces{",
" Iface: nil",
" Force: true",
"}",
)
test(
t,
"non-nil interface in named struct",
interfaces{Iface: int(100)},
"github.com/dogmatiq/dapper_test.interfaces{",
" Iface: int(100)",
" Force: false",
"}",
)
test(
t,
"nil interface in anonymous struct",
struct {
Iface any
}{},
"{",
" Iface: any(nil)",
"}",
)
test(
t,
"non-nil interface in anonymous struct",
struct {
Iface any
}{uint(100)},
"{",
" Iface: uint(100)",
"}",
)
}