-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathassert.go
63 lines (55 loc) · 1.22 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
package zutils
import (
"fmt"
)
var Assert = new(assertUtil)
type assertUtil struct{}
func (u *assertUtil) True(a bool, msg ...interface{}) {
if !a {
u.raise("assert.True", msg)
}
}
func (u *assertUtil) False(a bool, msg ...interface{}) {
if a {
u.raise("assert.False", msg)
}
}
func (u *assertUtil) Equal(a, b interface{}, msg ...interface{}) {
if a != b {
u.raise("assert.Equal", msg)
}
}
func (u *assertUtil) NotEqual(a, b interface{}, msg ...interface{}) {
if a == b {
u.raise("assert.NotEqual", msg)
}
}
func (u *assertUtil) Nil(a interface{}, msg ...interface{}) {
if a != nil {
u.raise("assert.Nil", msg)
}
}
func (u *assertUtil) NotNil(a interface{}, msg ...interface{}) {
if a == nil {
u.raise("assert.NotNil", msg)
}
}
func (u *assertUtil) Zero(a interface{}, msg ...interface{}) {
if !Reflect.IsZero(a) {
u.raise("assert.Zero", msg)
}
}
func (u *assertUtil) NotZero(a interface{}, msg ...interface{}) {
if Reflect.IsZero(a) {
u.raise("assert.NotZero", msg)
}
}
func (u *assertUtil) raise(def string, msg []interface{}) {
if len(msg) == 0 {
panic(def)
} else if len(msg) == 1 {
panic(def + " " + msg[0].(string))
} else {
panic(def + " " + fmt.Sprintf(msg[0].(string), msg[1:]...))
}
}