-
Notifications
You must be signed in to change notification settings - Fork 22
/
assert.go
66 lines (50 loc) · 1.01 KB
/
assert.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
package assert
import "testing"
func Equal[T comparable](t *testing.T, a, b T) {
t.Helper()
if a != b {
t.Errorf("expected `%v` to equal `%v`", a, b)
}
}
func True(t *testing.T, b bool) {
t.Helper()
if !b {
t.Error("expected `false` to be `true`")
}
}
func False(t *testing.T, b bool) {
t.Helper()
if b {
t.Error("expected `true` to be `false`")
}
}
func Nil(t *testing.T, v interface{}) {
t.Helper()
if v != nil {
t.Errorf("expected `%v` to equal `nil`", v)
}
}
func NotNil(t *testing.T, v interface{}) {
t.Helper()
if v == nil {
t.Error("expected `nil` not to equal `nil`")
}
}
func SliceEqual[T comparable](t *testing.T, a, b []T) {
t.Helper()
if len(a) != len(b) {
t.Errorf("expected `%v` to equal `%v` but lengths differ", a, b)
return
}
for i, v := range a {
if v != b[i] {
t.Errorf("expected `%v` to equal `%v`", a, b)
}
}
}
func Empty[S any, T []S | ~string](t *testing.T, items T) {
t.Helper()
if len(items) != 0 {
t.Errorf("expected `%v` to be empty", items)
}
}