/
utils.go
55 lines (45 loc) · 974 Bytes
/
utils.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
package test
import (
"testing"
)
func IsError(t *testing.T, err error) {
if err == nil {
t.Fatalf("%q", err)
}
}
func CheckErr(t *testing.T, err error) {
if err != nil {
t.Fatalf("%q", err)
}
}
func WantErr(t *testing.T, err error) {
if err == nil {
t.Fatalf("Wanted error, got nil")
}
}
func CheckEqS(t *testing.T, found string, wanted string) {
if found != wanted {
t.Fatalf(`Wanted: %q, Found: %q`, wanted, found)
}
}
func CheckEqN(t *testing.T, found int, wanted int) {
if found != wanted {
t.Fatalf(`Wanted: %d, Found: %d`, wanted, found)
}
}
// Equal tells whether a and b contain the same elements.
// A nil argument is equivalent to an empty slice.
func CheckEqualStringArr(t *testing.T, found []string, wanted []string) {
equal := true
if len(found) != len(wanted) {
equal = false
}
for i, v := range found {
if v != wanted[i] {
equal = false
}
}
if !equal {
t.Fatalf("Wanted: %q, Found: %q", wanted, found[0])
}
}