-
Notifications
You must be signed in to change notification settings - Fork 2
/
yaml_test.go
77 lines (68 loc) · 1.87 KB
/
yaml_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 yaml
import (
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func Test_isHashable(t *testing.T) {
tests := []struct {
val any
want bool
}{
// Primitives
{val: nil, want: true},
{val: 0, want: true},
{val: int64(0), want: true},
{val: "foobar", want: true},
// Complex types
{val: struct{ val [1]string }{}, want: true},
{val: chan int(nil), want: true},
// Pointers
{val: new(int), want: true},
{val: new(int64), want: true},
{val: new(string), want: true},
{val: new(struct{ val [1]string }), want: true},
{val: new(func()), want: true},
{val: new(chan int), want: true},
{val: new(map[string]string), want: true},
{val: new([]string), want: true},
// Not hashable.
{val: map[string]string{}, want: false},
{val: []map[string]string{}, want: false},
{val: [1]map[string]string{}, want: false},
{val: []string{}, want: false},
{val: [1][]string{}, want: false},
{val: (func())(nil), want: false},
{val: [1]func(){}, want: false},
{val: struct{ val map[string]string }{}, want: false},
{val: struct{ val [0]map[string]string }{}, want: false},
{val: struct{ val [1]map[string]string }{}, want: false},
{val: struct{ val []string }{}, want: false},
{val: struct{ val [0][]string }{}, want: false},
{val: struct{ val [1][]string }{}, want: false},
{val: struct{ val func() }{}, want: false},
{val: struct{ val [0]func() }{}, want: false},
{val: struct{ val [1]func() }{}, want: false},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
defer func() {
t.Logf("Type: %T, value: %#v", tt.val, tt.val)
}()
a := require.New(t)
check := a.Panics
if tt.want {
check = a.NotPanics
}
check(func() {
_ = map[any]struct{}{
tt.val: {},
}
})
v := reflect.ValueOf(tt.val)
a.Equal(tt.want, isHashable(v))
})
}
}