-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.go
More file actions
123 lines (91 loc) · 2.05 KB
/
assert.go
File metadata and controls
123 lines (91 loc) · 2.05 KB
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
package assert
import (
"errors"
"reflect"
"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. Expected: %v, Recieved: %v", name, b, a)
}
return equals
}
func EqualsArray[T comparable](t *testing.T, a []T, b []T, name string) bool {
t.Helper()
equals := reflect.DeepEqual(a, b)
if !equals {
t.Errorf("%v is incorrect. Expected: %v, Recieved: %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. Expected: %v, Recieved: %v", name, b, value)
}
return equals
}
func GetterArray[T comparable](t *testing.T, a func() []T, b []T, name string) bool {
t.Helper()
value := a()
equals := reflect.DeepEqual(value, b)
if !equals {
t.Errorf("%v is incorrect. Expected: %v, Recieved: %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. Expected: %v, Recieved: %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. Expected: %v, Recieved: %v", name, b, value)
}
return !equals
}