-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathqunit.go
More file actions
236 lines (204 loc) · 6.52 KB
/
Copy pathqunit.go
File metadata and controls
236 lines (204 loc) · 6.52 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package qunit
//GopherJS Bindings for qunitjs.com
import "github.com/gopherjs/gopherjs/js"
type QUnitAssert struct {
*js.Object
}
type DoneCallbackObject struct {
*js.Object
Failed int `js:"failed"`
Passed int `js:"passed"`
Total int `js:"total"`
Runtime int `js:"runtime"`
}
type LogCallbackObject struct {
*js.Object
result bool `js:"result"`
actual *js.Object `js:"actual"`
expected *js.Object `js:"expected"`
message string `js:"message"`
source string `js:"source"`
}
type ModuleStartCallbackObject struct {
*js.Object
name string `js:"name"`
}
type ModuleDoneCallbackObject struct {
*js.Object
name string `js:"name"`
failed int `js:"failed"`
passed int `js:"passed"`
total int `js:"total"`
}
type TestDoneCallbackObject struct {
*js.Object
name string `js:"name"`
module string `js:"module"`
failed int `js:"failed"`
passed int `js:"passed"`
total int `js:"total"`
duration int `js:"duration"`
}
type TestStartCallbackObject struct {
*js.Object
name string `js:"name"`
module string `js:"module"`
}
func (qa QUnitAssert) DeepEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("deepEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) Equal(actual interface{}, expected interface{}, message string) bool {
return qa.Call("equal", actual, expected, message).Bool()
}
func (qa QUnitAssert) NotDeepEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("notDeepEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) NotEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("notEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) NotPropEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("notPropEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) PropEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("propEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) NotStrictEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("notStrictEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) Ok(state interface{}, message string) bool {
return qa.Call("ok", state, message).Bool()
}
func (qa QUnitAssert) StrictEqual(actual interface{}, expected interface{}, message string) bool {
return qa.Call("strictEqual", actual, expected, message).Bool()
}
func (qa QUnitAssert) ThrowsExpected(block func() interface{}, expected interface{}, message string) *js.Object {
return qa.Call("throwsExpected", block, expected, message)
}
func (qa QUnitAssert) Throws(block func() interface{}, message string) *js.Object {
return qa.Call("throws", block, message)
}
func (qa QUnitAssert) Async() func() {
// Use a closure to wrap around the async javascript object
asyncObj := qa.Call("async")
return func() {
asyncObj.Invoke()
}
}
//start QUnit static methods
func Test(name string, testFn func(QUnitAssert)) {
js.Global.Get("QUnit").Call("test", name, func(e *js.Object) {
testFn(QUnitAssert{Object: e})
})
}
func TestExpected(title string, expected int, testFn func(assert QUnitAssert) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("test", title, expected, func(e *js.Object) {
testFn(QUnitAssert{Object: e})
})
return t
}
func Ok(state interface{}, message string) *js.Object {
return js.Global.Get("QUnit").Call("ok", state, message)
}
func Start() *js.Object {
return js.Global.Get("QUnit").Call("start")
}
func StartDecrement(decrement int) *js.Object {
return js.Global.Get("QUnit").Call("start", decrement)
}
func Stop() *js.Object {
return js.Global.Get("QUnit").Call("stop")
}
func StopIncrement(increment int) *js.Object {
return js.Global.Get("QUnit").Call("stop", increment)
}
func Begin(callbackFn func() interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("begin", func() {
callbackFn()
})
return t
}
func Done(callbackFn func(details DoneCallbackObject) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("done", func(e *js.Object) {
callbackFn(DoneCallbackObject{Object: e})
})
return t
}
func Log(callbackFn func(details LogCallbackObject) interface{}) *js.Object {
/*
2do:
t := js.Global.Get("QUnit").Call("log", func(e *js.Object) {
callbackFn(LogCallbackObject{Object: e})
})
*/
t := js.Global.Get("QUnit").Call("log", callbackFn)
return t
}
func ModuleDone(callbackFn func(details ModuleDoneCallbackObject) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("moduleDone", func(e *js.Object) {
callbackFn(ModuleDoneCallbackObject{Object: e})
})
return t
}
func ModuleStart(callbackFn func(name string) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("moduleStart", func(e *js.Object) {
callbackFn(e.String())
})
return t
}
func TestDone(callbackFn func(details TestDoneCallbackObject) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("testDone", func(e *js.Object) {
callbackFn(TestDoneCallbackObject{Object: e})
})
return t
}
func TestStart(callbackFn func(details TestStartCallbackObject) interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("testStart", func(e *js.Object) {
callbackFn(TestStartCallbackObject{Object: e})
})
return t
}
func AsyncTestExpected(name string, expected interface{}, testFn func() interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("asyncTestExpected", name, expected, func() {
testFn()
})
return t
}
func AsyncTest(name string, testFn func() interface{}) *js.Object {
t := js.Global.Get("QUnit").Call("asyncTest", name, func() {
testFn()
})
return t
}
func Expect(amount int) *js.Object {
return js.Global.Get("QUnit").Call("expect", amount)
}
func Equiv(a interface{}, b interface{}) *js.Object {
return js.Global.Get("QUnit").Call("equiv", a, b)
}
func Module(name string) *js.Object {
return js.Global.Get("QUnit").Call("module", name)
}
type Lifecycle interface {
Setup()
Teardown()
}
func ModuleLifecycle(name string, lc Lifecycle) *js.Object {
o := js.Global.Get("Object").New()
if lc.Setup != nil {
o.Set("setup", lc.Setup)
}
if lc.Teardown != nil {
o.Set("teardown", lc.Teardown)
}
return js.Global.Get("QUnit").Call("module", name, o)
}
type Raises struct {
*js.Object
Raises *js.Object `js:"raises"`
}
func Push(result interface{}, actual interface{}, expected interface{}, message string) *js.Object {
return js.Global.Get("QUnit").Call("push", result, actual, expected, message)
}
func Reset() *js.Object {
return js.Global.Get("QUnit").Call("reset")
}