-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils_test.go
62 lines (52 loc) · 1.17 KB
/
utils_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
package console
import (
"cmp"
"testing"
)
func AssertZero[E comparable](t *testing.T, v E) {
t.Helper()
var zero E
if v != zero {
t.Errorf("expected zero value, got %v", v)
}
}
func AssertEqual[E comparable](t *testing.T, expected, value E) {
t.Helper()
if expected != value {
t.Errorf("expected %v, got %v", expected, value)
}
}
func AssertNotEqual[E comparable](t *testing.T, expected, value E) {
t.Helper()
if expected == value {
t.Errorf("expected to be different, got %v", value)
}
}
func AssertGreaterOrEqual[E cmp.Ordered](t *testing.T, expected, value E) {
t.Helper()
if expected > value {
t.Errorf("expected to be %v to be greater than %v", value, expected)
}
}
func AssertNoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Errorf("expected no error, got %q", err.Error())
}
}
func AssertError(t *testing.T, err error) {
t.Helper()
if err == nil {
t.Error("expected an error, got nil")
}
}
// func AssertNil(t *testing.T, value any) {
// t.Helper()
// if value != nil {
// t.Errorf("expected nil, got %v", value)
// }
// }
type writerFunc func([]byte) (int, error)
func (w writerFunc) Write(b []byte) (int, error) {
return w(b)
}