-
Notifications
You must be signed in to change notification settings - Fork 22
/
assert.go
64 lines (53 loc) · 937 Bytes
/
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
package expect
import (
"fmt"
"reflect"
"database/sql"
)
func Nil(x any) {
if x != nil {
panic(fmt.Sprintf("expected nil; got %v", x))
}
}
func NotNil(x any) {
if x == nil {
panic(x)
}
}
func Equal(x, y any) {
if x == y {
return
}
yAsXType := reflect.ValueOf(y).Convert(reflect.TypeOf(x)).Interface()
if !reflect.DeepEqual(x, yAsXType) {
panic(fmt.Sprintf("%v != %v", x, y))
}
}
func StrictlyEqual(x, y any) {
if x != y {
panic(fmt.Sprintf("%s != %s", x, y))
}
}
func OneRowAffected(r sql.Result) {
count, err := r.RowsAffected()
Nil(err)
if count != 1 {
panic(count)
}
}
func True(b bool) {
if !b {
panic(b)
}
}
var Ok = True
func False(b bool) {
if b {
panic(b)
}
}
func Zero(x any) {
if x != reflect.Zero(reflect.TypeOf(x)).Interface() {
panic(x)
}
}