-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactually_test.go
95 lines (82 loc) · 2.09 KB
/
actually_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
85
86
87
88
89
90
91
92
93
94
95
package actually
import (
"testing"
)
func TestGot(t *testing.T) {
i := 12
a := Got(i).Expect(i)
if a.got != i {
t.Errorf("`Got()` was broken. Expected:%#v, but Actual:%#v", i, a.got)
}
if a.expect != i {
t.Errorf("`Expect()` was broken. Expected:%#v, but Actual:%#v", i, a.expect)
}
}
func TestActuallyGot(t *testing.T) {
i := 12
a := &testingA{}
a.Got(i).Expect(i)
if a.got != i {
t.Errorf("`actually.Got()` was broken. Expected:%#v, but Actual:%#v", i, a.got)
}
if a.expect != i {
t.Errorf("`actually.Expect()` was broken. Expected:%#v, but Actual:%#v", i, a.expect)
}
}
func TestExpect(t *testing.T) {
i := 13
a := Expect(i).Got(i)
if a.got != i {
t.Errorf("`Got()` was broken. Expected:%#v, but Actual:%#v", i, a.got)
}
if a.expect != i {
t.Errorf("`Expect()` was broken. Expected:%#v, but Actual:%#v", i, a.expect)
}
if a.failNow != nil && *a.failNow != false {
t.Errorf("`FailNotNow()` was broken. Expected:%#v, but Actual:%#v", false, a.failNow)
}
}
func TestActuallyExpect(t *testing.T) {
i := 13
a := &testingA{}
a.Expect(i).Got(i)
if a.got != i {
t.Errorf("`actually.Got()` was broken. Expected:%#v, but Actual:%#v", i, a.got)
}
if a.expect != i {
t.Errorf("`actually.Expect()` was broken. Expected:%#v, but Actual:%#v", i, a.expect)
}
}
func TestDuplicateCall(t *testing.T) {
f := false
defer func() {
err := recover()
if err != panicReason_CalledGotTwice {
t.Errorf("expect error %s, but got %+v", panicReason_CalledGotTwice, err)
}
f = true
}()
Got(1).Got(2) // duplicate calling Got should be panic
if !f {
t.Error("panic wouldn't happen")
}
f = false
defer func() {
err := recover()
if err != panicReason_CalledExpectTwice {
t.Errorf("expect error %s, but got %+v", panicReason_CalledExpectTwice, err)
}
f = true
}()
Expect(1).Expect(1) // duplicate calling Expect should be panic
if !f {
t.Error("panic wouldn't happen")
}
}
func TestExpectf(t *testing.T) {
Expectf("%s def", "abc").Got("abc def").Same(t)
}
func TestActuallyExpectf(t *testing.T) {
a := &testingA{}
a.Expectf("%s def", "abc").Got("abc def").Same(t)
}