-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_funcs_test.go
112 lines (95 loc) · 2 KB
/
helper_funcs_test.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
100
101
102
103
104
105
106
107
108
109
110
111
112
package xl8r
import (
"reflect"
"testing"
)
/*******************************
* Test Helper Functions Below *
*******************************/
const tFail = "test failed"
func failTest(t *testing.T, msgAndArgs0 ...any) {
t.Helper()
if len(msgAndArgs0) == 0 {
t.Errorf(tFail)
}
var msg string
var msgOK bool
msg, msgOK = msgAndArgs0[0].(string)
if !msgOK {
t.Errorf(tFail)
}
args := msgAndArgs0[1:]
t.Errorf(msg, args...)
}
func assrtEqual(t *testing.T, oe, oa any, msgAndArgs0 ...any) {
t.Helper()
if reflect.DeepEqual(oe, oa) {
return
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected values to be equal, but\n\texpected value was %v\n\tactual value was %v", oe, oa)
return
}
failTest(t, msgAndArgs0...)
}
func assrtEqualAny(t *testing.T, oe0 []any, oa any, msgAndArgs0 ...any) {
t.Helper()
if len(oe0) == 0 {
t.Errorf("impossible - empty assertion for EqualAny")
return
}
for _, oe := range oe0 {
if oe == oa {
return
}
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected value to equal one of %v, but\n\tactual value was %v", oe0, oa)
return
}
failTest(t, msgAndArgs0...)
}
func assrtFalse(t *testing.T, o any, msgAndArgs0 ...any) {
t.Helper()
if o == false {
return
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected bool false, but actual value was %v", o)
return
}
failTest(t, msgAndArgs0...)
}
func assrtTrue(t *testing.T, o any, msgAndArgs0 ...any) {
t.Helper()
if o == true {
return
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected bool true, but actual value was %v", o)
return
}
failTest(t, msgAndArgs0...)
}
func assrtNil(t *testing.T, o any, msgAndArgs0 ...any) {
t.Helper()
if o == nil {
return
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected nil, but actual value was %v", o)
return
}
failTest(t, msgAndArgs0...)
}
func assrtNotNil(t *testing.T, o any, msgAndArgs0 ...any) {
t.Helper()
if o != nil {
return
}
if len(msgAndArgs0) == 0 {
t.Errorf("expected non-nil, but actual value was nil")
return
}
failTest(t, msgAndArgs0...)
}