1
1
import JavaScriptKit
2
2
3
- Literal_Conversion: do {
3
+ test ( " Literal Conversion " ) {
4
4
let global = JSObjectRef . global
5
5
let inputs : [ JSValue ] = [
6
6
. boolean( true ) ,
@@ -27,11 +27,9 @@ Literal_Conversion: do {
27
27
try expectEqual ( got, input)
28
28
}
29
29
}
30
- } catch {
31
- print ( error)
32
30
}
33
31
34
- Object_Conversion: do {
32
+ test ( " Object Conversion " ) {
35
33
// Notes: globalObject1 is defined in JavaScript environment
36
34
//
37
35
// ```js
@@ -70,12 +68,9 @@ Object_Conversion: do {
70
68
}
71
69
72
70
try expectEqual ( getJSValue ( this: globalObject1Ref, name: " undefined_prop " ) , . undefined)
73
-
74
- } catch {
75
- print ( error)
76
71
}
77
72
78
- Value_Construction: do {
73
+ test ( " Value Construction " ) {
79
74
let globalObject1 = getJSValue ( this: . global, name: " globalObject1 " )
80
75
let globalObject1Ref = try expectObject ( globalObject1)
81
76
let prop_2 = getJSValue ( this: globalObject1Ref, name: " prop_2 " )
@@ -85,11 +80,9 @@ Value_Construction: do {
85
80
let prop_7 = getJSValue ( this: globalObject1Ref, name: " prop_7 " )
86
81
try expectEqual ( Double . construct ( from: prop_7) , 3.14 )
87
82
try expectEqual ( Float . construct ( from: prop_7) , 3.14 )
88
- } catch {
89
- print ( error)
90
83
}
91
84
92
- Array_Iterator: do {
85
+ test ( " Array Iterator " ) {
93
86
let globalObject1 = getJSValue ( this: . global, name: " globalObject1 " )
94
87
let globalObject1Ref = try expectObject ( globalObject1)
95
88
let prop_4 = getJSValue ( this: globalObject1Ref, name: " prop_4 " )
@@ -100,7 +93,7 @@ Array_Iterator: do {
100
93
try expectEqual ( Array ( array) , expectedProp_4)
101
94
}
102
95
103
- Array_RandomAccessCollection: do {
96
+ test ( " Array RandomAccessCollection " ) {
104
97
let globalObject1 = getJSValue ( this: . global, name: " globalObject1 " )
105
98
let globalObject1Ref = try expectObject ( globalObject1)
106
99
let prop_4 = getJSValue ( this: globalObject1Ref, name: " prop_4 " )
@@ -111,7 +104,7 @@ Array_RandomAccessCollection: do {
111
104
try expectEqual ( [ array [ 0 ] , array [ 1 ] , array [ 2 ] , array [ 3 ] ] , expectedProp_4)
112
105
}
113
106
114
- Value_Decoder: do {
107
+ test ( " Value Decoder " ) {
115
108
struct GlobalObject1 : Codable {
116
109
struct Prop1 : Codable {
117
110
let nested_prop : Int
@@ -131,7 +124,7 @@ Value_Decoder: do {
131
124
try expectEqual ( globalObject1. prop_7, 3.14 )
132
125
}
133
126
134
- Function_Call: do {
127
+ test ( " Function Call " ) {
135
128
// Notes: globalObject1 is defined in JavaScript environment
136
129
//
137
130
// ```js
@@ -173,12 +166,9 @@ Function_Call: do {
173
166
try expectEqual ( func6 ( true , 1 , 2 ) , . number( 1 ) )
174
167
try expectEqual ( func6 ( false , 1 , 2 ) , . number( 2 ) )
175
168
try expectEqual ( func6 ( true , " OK " , 2 ) , . string( " OK " ) )
176
-
177
- } catch {
178
- print ( error)
179
169
}
180
170
181
- Host_Function_Registration: do {
171
+ test ( " Host Function Registration " ) {
182
172
// ```js
183
173
// global.globalObject1 = {
184
174
// ...
@@ -221,11 +211,9 @@ Host_Function_Registration: do {
221
211
try expectEqual ( hostFunc2 ( 3 ) , . number( 6 ) )
222
212
_ = try expectString ( hostFunc2 ( true ) )
223
213
hostFunc2. release ( )
224
- } catch {
225
- print ( error)
226
214
}
227
215
228
- New_Object_Construction: do {
216
+ test ( " New Object Construction " ) {
229
217
// ```js
230
218
// global.Animal = function(name, age, isCat) {
231
219
// this.name = name
@@ -247,11 +235,9 @@ New_Object_Construction: do {
247
235
let dog1 = objectConstructor. new ( " Pochi " , 3 , false )
248
236
let dog1Bark = try expectFunction ( getJSValue ( this: dog1, name: " bark " ) )
249
237
try expectEqual ( dog1Bark ( ) , . string( " wan " ) )
250
- } catch {
251
- print ( error)
252
238
}
253
239
254
- Call_Function_With_This: do {
240
+ test ( " Call Function With This " ) {
255
241
// ```js
256
242
// global.Animal = function(name, age, isCat) {
257
243
// this.name = name
@@ -275,18 +261,15 @@ Call_Function_With_This: do {
275
261
// Call with this
276
262
let gotIsCat = getIsCat ( this: cat1)
277
263
try expectEqual ( gotIsCat, . boolean( true ) )
278
-
279
- } catch {
280
- print ( error)
281
264
}
282
265
283
- Object_Conversion: do {
284
- let array1 = [ 1 , 2 , 3 ]
285
- let jsArray1 = array1. jsValue ( ) . object!
286
- try expectEqual ( jsArray1. length, . number( 3 ) )
287
- try expectEqual ( jsArray1 [ 0 ] , . number( 1 ) )
288
- try expectEqual ( jsArray1 [ 1 ] , . number( 2 ) )
289
- try expectEqual ( jsArray1 [ 2 ] , . number( 3 ) )
266
+ test ( " Object Conversion " ) {
267
+ let array1 = [ 1 , 2 , 3 ]
268
+ let jsArray1 = array1. jsValue ( ) . object!
269
+ try expectEqual ( jsArray1. length, . number( 3 ) )
270
+ try expectEqual ( jsArray1 [ 0 ] , . number( 1 ) )
271
+ try expectEqual ( jsArray1 [ 1 ] , . number( 2 ) )
272
+ try expectEqual ( jsArray1 [ 2 ] , . number( 3 ) )
290
273
291
274
let array2 : [ JSValueConvertible ] = [ 1 , " str " , false ]
292
275
let jsArray2 = array2. jsValue ( ) . object!
@@ -296,9 +279,9 @@ Object_Conversion: do {
296
279
try expectEqual ( jsArray2 [ 2 ] , . boolean( false ) )
297
280
_ = jsArray2. push!( 5 )
298
281
try expectEqual ( jsArray2. length, . number( 4 ) )
299
- _ = jsArray2. push!( jsArray1)
282
+ _ = jsArray2. push!( jsArray1)
300
283
301
- try expectEqual ( jsArray2 [ 4 ] , . object( jsArray1) )
284
+ try expectEqual ( jsArray2 [ 4 ] , . object( jsArray1) )
302
285
303
286
let dict1 : [ String : JSValueConvertible ] = [
304
287
" prop1 " : 1 ,
@@ -307,11 +290,9 @@ Object_Conversion: do {
307
290
let jsDict1 = dict1. jsValue ( ) . object!
308
291
try expectEqual ( jsDict1. prop1, . number( 1 ) )
309
292
try expectEqual ( jsDict1. prop2, . string( " foo " ) )
310
- } catch {
311
- print ( error)
312
293
}
313
294
314
- ObjectRef_Lifetime: do {
295
+ test ( " ObjectRef Lifetime " ) {
315
296
// ```js
316
297
// global.globalObject1 = {
317
298
// "prop_1": {
@@ -332,8 +313,6 @@ ObjectRef_Lifetime: do {
332
313
try expectEqual ( ref1. prop_2, . number( 2 ) )
333
314
try expectEqual ( ref2. prop_2, . number( 2 ) )
334
315
identity. release ( )
335
- } catch {
336
- print ( error)
337
316
}
338
317
339
318
func closureScope( ) -> ObjectIdentifier {
@@ -343,10 +322,8 @@ func closureScope() -> ObjectIdentifier {
343
322
return result
344
323
}
345
324
346
- Closure_Identifiers: do {
325
+ test ( " Closure Identifiers " ) {
347
326
let oid1 = closureScope ( )
348
327
let oid2 = closureScope ( )
349
328
try expectEqual ( oid1, oid2)
350
- } catch {
351
- print ( error)
352
329
}
0 commit comments