forked from go-rel/rel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
87 lines (74 loc) · 1.23 KB
/
util_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
78
79
80
81
82
83
84
85
86
87
package rel
import (
"errors"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMust(t *testing.T) {
assert.Panics(t, func() {
must(errors.New("error"))
})
}
func TestMustTrue(t *testing.T) {
assert.Panics(t, func() {
mustTrue(false, "error")
})
}
func TestIsZero(t *testing.T) {
tests := []any{
nil,
false,
"",
int(0),
int8(0),
int16(0),
int32(0),
int64(0),
uint(0),
uint8(0),
uint16(0),
uint32(0),
uint64(0),
uintptr(0),
float32(0),
float64(0),
time.Time{},
struct{}{},
}
for i := range tests {
t.Run("IsZero", func(t *testing.T) {
assert.True(t, isZero(tests[i]))
})
}
}
func TestIsDeepZero(t *testing.T) {
v := struct {
A bool
B int
C uint
D float32
E complex64
F [1]int
G *string
H string
J struct {
JA int
}
}{}
assert.True(t, isDeepZero(reflect.ValueOf(v), 1))
}
func TestIsDeepZero_notZeroArray(t *testing.T) {
v := [1]bool{true}
assert.False(t, isDeepZero(reflect.ValueOf(v), 1))
}
func TestIsDeepZero_notZeroStruct(t *testing.T) {
v := struct {
A bool
}{true}
assert.False(t, isDeepZero(reflect.ValueOf(v), 1))
}
func TestIsDeepZero_reflectInvalid(t *testing.T) {
assert.True(t, isDeepZero(reflect.Value{}, 1))
}