-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_test.go
47 lines (40 loc) · 961 Bytes
/
test_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
package sugar_test
import (
"fmt"
"strings"
"testing"
)
func fail(t *testing.T, failMsg string, tags ...string) {
t.Helper()
if len(tags) == 0 {
t.Error(failMsg)
} else {
t.Errorf("%s, tags: %s", failMsg, strings.Join(tags, ", "))
}
}
func AssertEqual[T comparable](t *testing.T, expected T, actual T, tags ...string) {
t.Helper()
if expected != actual {
fail(t, fmt.Sprintf("expected: %v, actual: %v", expected, actual), tags...)
}
}
func AssertSliceEqual[T comparable](t *testing.T, expected []T, actual []T) {
t.Helper()
if expected == nil || actual == nil {
if expected == nil && actual == nil {
return
}
t.Errorf("expected: %v, actual: %v", expected, actual)
return
}
if len(expected) != len(actual) {
t.Errorf("expected: %v, actual: %v", expected, actual)
return
}
for i := 0; i < len(expected); i++ {
if expected[i] != actual[i] {
t.Errorf("expected: %v, actual: %v", expected, actual)
return
}
}
}