-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.go
99 lines (73 loc) · 1.55 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
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
package assert
import (
"errors"
"testing"
)
func Equals[T comparable](t *testing.T, a T, b T, name string) bool {
t.Helper()
equals := a == b
if !equals {
t.Errorf("%v is incorrect. Recieved: %v, Expected: %v", name, b, a)
}
return equals
}
func Getter[T comparable](t *testing.T, a func() T, b T, name string) bool {
t.Helper()
value := a()
equals := value == b
if !equals {
t.Errorf("%v is incorrect. Recieved: %v, Expected: %v", name, b, value)
}
return equals
}
func True(t *testing.T, value bool, message string) bool {
t.Helper()
if !value {
t.Error(message)
}
return value
}
func False(t *testing.T, value bool, message string) bool {
t.Helper()
if value {
t.Error(message)
}
return !value
}
func NoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
}
func MustError(t *testing.T, err error, message string) {
t.Helper()
if err == nil {
t.Fatal(message)
}
}
func ErrorIs(t *testing.T, err error, target error, message string) bool {
t.Helper()
equals := errors.Is(err, target)
if !equals {
t.Error(message)
}
return equals
}
func NotEquals[T comparable](t *testing.T, a T, b T, name string) bool {
t.Helper()
notEquals := a != b
if !notEquals {
t.Errorf("%v is incorrect. Recieved: %v, Expected: %v", name, b, a)
}
return notEquals
}
func NotEqualsEval[T comparable](t *testing.T, a func() T, b T, name string) bool {
t.Helper()
value := a()
equals := value == b
if equals {
t.Errorf("%v is incorrect. Recieved: %v, Expected: %v", name, b, value)
}
return !equals
}