-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
84 lines (69 loc) · 1.6 KB
/
helpers_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
package actually
import (
"fmt"
"strings"
"testing"
)
func TestSkip(t *testing.T) {
Got(1).NotNil(t)
Skip(t, "Skip reason")
Got(2).NotNil(t)
Got(3).NotNil(t)
}
func TestTestName(t *testing.T) {
a := Got(1).Name("foo").NotNil(t)
aa := Got(a.name).Expect("foo").Same(t, "bar")
aaa := Got(aa.name).Expect("bar").Name("baz").Same(t, "aiko")
Got(aaa.name).Expect("baz.aiko").Same(t)
}
func TestX(t *testing.T) {
a := Got("beer").Expect("deer").X()
Got(a.showRawData).True(t)
}
func TestDiff(t *testing.T) {
got := "\n" + Diff("bar", "bug")
expect := `
--- a
+++ b
@@ -1 +1 @@
-bar
+bug
`
Got(got).Expect(expect).X().Same(t)
}
func TestDump(t *testing.T) {
got := map[string]int{
"foo": 256,
}
expect := "map[string]int:1 {\n" +
" \"foo\": 256,\n" +
"}"
Got(Dump(got)).Expect(expect).X().Same(t)
}
func TestFi(t *testing.T) {
isFailed := Got(nil).Nil(t).Fi()
Got(isFailed).False(t) // Passed, so it should be `false`
stubConfirm(t, func() {
if fi := Got(isFailed).True(t).Fi(); !fi {
t.Fatal("If the test got fail, fi must return `true`. Actually, got `false`, somehow")
}
}, message_ExpectTrue)
}
func TestDebug(t *testing.T) {
a := Got(1).Debug("label", 123)
a.t = t
stub()
a.fail(a.wi(), "reason")
if !strings.Contains(fmt.Sprintf("%#v", stubWitness), `{"label":[]*obj.Object{(*obj.Object)(`) {
t.Error("not include debug info")
}
}
func TestDebugMultipleInfo(t *testing.T) {
a := Got(1).Debug("label", 123, 456)
a.t = t
stub()
a.fail(a.wi(), "reason")
if !strings.Contains(fmt.Sprintf("%#v", stubWitness), `), (*obj.Object)(`) {
t.Error("not include 2nd debug info")
}
}