-
Notifications
You must be signed in to change notification settings - Fork 2
/
must_test.go
191 lines (150 loc) · 2.98 KB
/
must_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package must_test
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/yyle88/must"
"github.com/yyle88/must/internal/tests"
)
func TestTrue(t *testing.T) {
must.True(true)
tests.ExpectPanic(t, func() {
must.True(false)
})
}
func TestDone(t *testing.T) {
must.Done(error(nil))
tests.ExpectPanic(t, func() {
must.Done(errors.New("wa"))
})
}
func TestNice(t *testing.T) {
require.Equal(t, 88, must.Nice(88))
require.Equal(t, "xyz", must.Nice("xyz"))
require.Equal(t, 3.1415926, must.Nice(3.1415926))
tests.ExpectPanic(t, func() {
must.Nice(0.0)
})
}
func TestZero(t *testing.T) {
must.Zero(0)
must.Zero("")
must.Zero(0.0)
tests.ExpectPanic(t, func() {
must.Zero(uint64(200))
})
}
func TestNone(t *testing.T) {
must.None(0)
must.None(0.0)
must.None("")
must.None(error(nil))
tests.ExpectPanic(t, func() {
must.None(errors.New("wa"))
})
}
func TestEquals(t *testing.T) {
must.Equals("abc", "abc")
must.Equals(123, 123)
must.Equals(0.8, 0.8)
tests.ExpectPanic(t, func() {
must.Equals("abc", "xyz")
})
}
func TestIs(t *testing.T) {
must.Is(123, 123)
must.Is("!", "!")
must.Is('!', '!')
must.Is(0.5, 0.5)
tests.ExpectPanic(t, func() {
must.Is(1, 2)
})
}
func TestOk(t *testing.T) {
must.Ok(1990)
tests.ExpectPanic(t, func() {
must.Ok("")
})
}
func TestOK(t *testing.T) {
must.OK("yyle")
must.OK(88)
must.OK(0.88)
must.OK(uint64(88))
must.OK('8')
tests.ExpectPanic(t, func() {
must.OK(0)
})
}
func TestTRUE(t *testing.T) {
must.TRUE(true)
tests.ExpectPanic(t, func() {
must.TRUE(false)
})
}
func TestFALSE(t *testing.T) {
must.FALSE(false)
tests.ExpectPanic(t, func() {
must.FALSE(true)
})
}
func TestFalse(t *testing.T) {
must.False(false)
tests.ExpectPanic(t, func() {
must.False(true)
})
}
func TestHave(t *testing.T) {
must.Have([]int{0, 1, 2, 3})
must.Have([]string{"abc", "xyz"})
must.Have([]float64{0.0})
tests.ExpectPanic(t, func() {
must.Have([]uint64{})
})
}
func TestLength(t *testing.T) {
must.Length([]int{0, 1, 2, 3}, 4)
must.Length([]string{"abc", "xyz"}, 2)
must.Length([]float64{0.0}, 1)
must.Length([]uint64{}, 0)
tests.ExpectPanic(t, func() {
must.Length([]any{"a", 1, 'x'}, 2)
})
}
func TestLen(t *testing.T) {
must.Len([]int{}, 0)
must.Len([]float64{0.1, 0.2}, 2)
tests.ExpectPanic(t, func() {
must.Len([]uint64{}, 88)
})
}
func TestIn(t *testing.T) {
must.In(1, []int{1, 2, 3})
must.In(2.0, []int{1, 2.0, 3})
tests.ExpectPanic(t, func() {
must.In("a", []string{"b", "c"})
})
}
func TestContains(t *testing.T) {
must.Contains([]string{"a", "b", "c"}, "a")
tests.ExpectPanic(t, func() {
must.Contains([]int{1, 2, 3}, 4)
})
}
type Example struct {
S string
}
func TestNull(t *testing.T) {
var example *Example
must.Null(example)
tests.ExpectPanic(t, func() {
must.Null(&Example{S: "abc"})
})
}
func TestFull(t *testing.T) {
must.Full(&Example{S: "abc"})
tests.ExpectPanic(t, func() {
var example *Example
must.Full(example)
})
}