-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactually.go
97 lines (80 loc) · 1.86 KB
/
actually.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
96
97
// Yet another pithy testing framework `actually`
package actually
import (
"fmt"
"sync"
"testing"
"github.com/google/go-cmp/cmp"
)
type debugInfoMap struct {
debugInfo []map[string][]any
mutex sync.RWMutex
}
type cmpOptList struct {
cmpOpts []cmp.Option
mutex sync.RWMutex
}
// testingA is a context of the test
type testingA struct {
got any
setGot bool
expect any
setExpect bool
t *testing.T
failNow *bool
showRawData bool
name string
failed bool
debugInfo debugInfoMap
cmpOpts cmpOptList
}
// Got sets the value you actually got. Got() creates *testingA and returns it.
func Got(g any) *testingA {
return &testingA{
got: g,
setGot: true,
}
}
// Got sets the value you actually got.
func (a *testingA) Got(g any) *testingA {
if a.setGot {
panic(panicReason_CalledGotTwice)
}
a.got = g
a.setGot = true
return a
}
// Expect sets the value you expect to be the same as the one you got.
// Expect creates *testingA and returns it.
func Expect(e any) *testingA {
return &testingA{
expect: e,
setExpect: true,
}
}
// Expect sets the value you expect to be the same as the one you got.
func (a *testingA) Expect(e any) *testingA {
if a.setExpect {
panic(panicReason_CalledExpectTwice)
}
a.expect = e
a.setExpect = true
return a
}
// Expectf sets the formatted string value you expect to be the same as the one you got.
// Expectf creates *testingA and returns it.
func Expectf(format string, e ...any) *testingA {
return &testingA{
expect: fmt.Sprintf(format, e...),
setExpect: true,
}
}
// Expectf sets the formatted string value you expect to be the same as the one you got.
func (a *testingA) Expectf(format string, e ...any) *testingA {
if a.setExpect {
panic(panicReason_CalledExpectTwice)
}
a.expect = fmt.Sprintf(format, e...)
a.setExpect = true
return a
}