-
Notifications
You must be signed in to change notification settings - Fork 0
/
goo_test.go
69 lines (53 loc) · 1.73 KB
/
goo_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
package goo
import (
"errors"
"testing"
"github.com/torfason/goo/assert"
)
func TestMain(t *testing.T) {
t.Run("assert.EqualInt", func(t *testing.T) {
assert.EqualInt(t, 1, 1, "A message is optional.")
})
t.Run("assert.Error", func(t *testing.T) {
assert.Error(t, errors.New("an error"), "A message is optional.")
})
// Test two ways of creating a slice
// AKA: make() is never needed (except for pre-allocating memory)
t.Run("assert.EqualSliceString", func(t *testing.T) {
// Init empty
x := []string{} // With curlies
y := make([]string, 0, 99) // With make(): cap is irrelevant for equality
assert.EqualSliceString(t, x, y)
// Init with elements, or append
x = []string{"zero", "one", "two"}
y = append(y, "zero", "one", "two")
assert.EqualSliceString(t, x, y)
// Append one slice to another
z := append(x, y...)
w := append(y, x...)
assert.EqualSliceString(t, z, w)
})
// Test two ways of creating a map
// AKA: make() is never needed (except for pre-allocating memory)
t.Run("assert.EqualMapStringString", func(t *testing.T) {
// Init empty
x := map[string]string{} // With curlies
y := make(map[string]string, 99) // With make(): cap is irrelevant for equality
assert.EqualMapStringString(t, x, y)
// Init with elements and/or add after init
x = map[string]string{"a": "Alpha", "b": "Beta"}
y["a"] = "Alpha"
y["b"] = "Beta"
assert.EqualMapStringString(t, x, y)
// Assign "" is (almost) equivalent to delete() !
x["b"] = ""
delete(y, "b")
assert.EqualString(t, x["b"], y["b"])
// But they can be distinguished with the ok param
xVal, xOK := x["b"]
yVal, yOK := y["b"]
assert.EqualString(t, xVal, yVal)
assert.True(t, xOK)
assert.False(t, yOK)
})
}