json-as 0.9.17 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,212 +1,140 @@
1
1
  import { JSON } from "json-as";
2
+ import { describe, expect, run } from "as-test/assembly";
2
3
  import {
3
- describe,
4
- expect,
5
- run
6
- } from "as-test/assembly";
7
- import { DerivedObject, Null, ObjWithStrangeKey, ObjectWithFloat, OmitIf, Player, Vec3 } from "./types";
4
+ DerivedObject,
5
+ Null,
6
+ ObjWithStrangeKey,
7
+ ObjectWithFloat,
8
+ OmitIf,
9
+ Player,
10
+ Vec3,
11
+ } from "./types";
8
12
 
9
13
  describe("Should serialize strings", () => {
14
+ expect(JSON.stringify("abcdefg")).toBe('"abcdefg"');
10
15
 
11
- expect(
12
- JSON.stringify("abcdefg")
13
- ).toBe("\"abcdefg\"");
16
+ expect(JSON.stringify('st"ring" w""ith quotes"')).toBe(
17
+ '"st\\"ring\\" w\\"\\"ith quotes\\""',
18
+ );
14
19
 
15
20
  expect(
16
- JSON.stringify('st"ring" w""ith quotes"')
17
- ).toBe('"st\\"ring\\" w\\"\\"ith quotes\\""');
18
-
19
- expect(
20
- JSON.stringify('string \"with random spa\nces and \nnewlines\n\n\n')
21
+ JSON.stringify('string "with random spa\nces and \nnewlines\n\n\n'),
21
22
  ).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
22
23
 
23
24
  expect(
24
- JSON.stringify('string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"')
25
- ).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\\\""')
26
-
25
+ JSON.stringify(
26
+ 'string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"',
27
+ ),
28
+ ).toBe(
29
+ '"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\\\""',
30
+ );
27
31
  });
28
32
 
29
33
  describe("Should serialize integers", () => {
34
+ expect(JSON.stringify(0)).toBe("0");
30
35
 
31
- expect(
32
- JSON.stringify(0)
33
- ).toBe("0");
34
-
35
- expect(
36
- JSON.stringify<u32>(100)
37
- ).toBe("100");
38
-
39
- expect(
40
- JSON.stringify<u64>(101)
41
- ).toBe("101");
36
+ expect(JSON.stringify<u32>(100)).toBe("100");
42
37
 
43
- expect(
44
- JSON.stringify<i32>(-100)
45
- ).toBe("-100");
38
+ expect(JSON.stringify<u64>(101)).toBe("101");
46
39
 
47
- expect(
48
- JSON.stringify<i64>(-101)
49
- ).toBe("-101");
40
+ expect(JSON.stringify<i32>(-100)).toBe("-100");
50
41
 
42
+ expect(JSON.stringify<i64>(-101)).toBe("-101");
51
43
  });
52
44
 
53
45
  describe("Should serialize floats", () => {
46
+ expect(JSON.stringify<f64>(7.23)).toBe("7.23");
54
47
 
55
- expect(
56
- JSON.stringify<f64>(7.23)
57
- ).toBe("7.23");
48
+ expect(JSON.stringify<f64>(10e2)).toBe("1000.0");
58
49
 
59
- expect(
60
- JSON.stringify<f64>(10e2)
61
- ).toBe("1000.0");
62
-
63
- expect(
64
- JSON.stringify<f64>(123456e-5)
65
- ).toBe("1.23456");
66
-
67
- expect(
68
- JSON.stringify<f64>(0.0)
69
- ).toBe("0.0");
50
+ expect(JSON.stringify<f64>(123456e-5)).toBe("1.23456");
70
51
 
71
- expect(
72
- JSON.stringify<f64>(-7.23)
73
- ).toBe("-7.23");
52
+ expect(JSON.stringify<f64>(0.0)).toBe("0.0");
74
53
 
75
- expect(
76
- JSON.stringify<f64>(1e-6)
77
- ).toBe("0.000001");
54
+ expect(JSON.stringify<f64>(-7.23)).toBe("-7.23");
78
55
 
79
- expect(
80
- JSON.stringify<f64>(1e-7)
81
- ).toBe("1e-7");
56
+ expect(JSON.stringify<f64>(1e-6)).toBe("0.000001");
82
57
 
83
- expect(
84
- JSON.parse<f64>("1E-7")
85
- ).toBe(1e-7);
58
+ expect(JSON.stringify<f64>(1e-7)).toBe("1e-7");
86
59
 
87
- expect(
88
- JSON.stringify<f64>(1e20)
89
- ).toBe("100000000000000000000.0");
60
+ expect(JSON.parse<f64>("1E-7")).toBe(1e-7);
90
61
 
91
- expect(
92
- JSON.stringify<f64>(1e21)
93
- ).toBe("1e+21");
62
+ expect(JSON.stringify<f64>(1e20)).toBe("100000000000000000000.0");
94
63
 
95
- expect(
96
- JSON.parse<f64>("1E+21")
97
- ).toBe(1e21);
64
+ expect(JSON.stringify<f64>(1e21)).toBe("1e+21");
98
65
 
99
- expect(
100
- JSON.parse<f64>("1e21")
101
- ).toBe(1e21);
66
+ expect(JSON.parse<f64>("1E+21")).toBe(1e21);
102
67
 
103
- expect(
104
- JSON.parse<f64>("1E21")
105
- ).toBe(1e21);
68
+ expect(JSON.parse<f64>("1e21")).toBe(1e21);
106
69
 
70
+ expect(JSON.parse<f64>("1E21")).toBe(1e21);
107
71
  });
108
72
 
109
73
  describe("Should serialize booleans", () => {
74
+ expect(JSON.stringify<bool>(true)).toBe("true");
110
75
 
111
- expect(
112
- JSON.stringify<bool>(true)
113
- ).toBe("true");
76
+ expect(JSON.stringify<bool>(false)).toBe("false");
114
77
 
115
- expect(
116
- JSON.stringify<bool>(false)
117
- ).toBe("false");
118
-
119
- expect(
120
- JSON.stringify<boolean>(true)
121
- ).toBe("true");
122
-
123
- expect(
124
- JSON.stringify<boolean>(false)
125
- ).toBe("false");
78
+ expect(JSON.stringify<boolean>(true)).toBe("true");
126
79
 
80
+ expect(JSON.stringify<boolean>(false)).toBe("false");
127
81
  });
128
82
 
129
83
  describe("Should serialize class inheritance", () => {
130
-
131
84
  const obj = new DerivedObject("1", "2");
132
85
 
133
- expect(
134
- JSON.stringify(obj)
135
- ).toBe("{\"a\":\"1\",\"b\":\"2\"}");
136
-
86
+ expect(JSON.stringify(obj)).toBe('{"a":"1","b":"2"}');
137
87
  });
138
88
 
139
89
  describe("Should serialize nulls", () => {
140
-
141
- expect(
142
- JSON.stringify<Null>(null)
143
- ).toBe("null");
144
-
90
+ expect(JSON.stringify<Null>(null)).toBe("null");
145
91
  });
146
92
 
147
-
148
93
  describe("Should serialize integer arrays", () => {
94
+ expect(JSON.stringify<u32[]>([0, 100, 101])).toBe("[0,100,101]");
149
95
 
150
- expect(
151
- JSON.stringify<u32[]>([0, 100, 101])
152
- ).toBe("[0,100,101]");
153
-
154
- expect(
155
- JSON.stringify<u64[]>([0, 100, 101])
156
- ).toBe("[0,100,101]");
157
-
158
- expect(
159
- JSON.stringify<i32[]>([0, 100, 101, -100, -101])
160
- ).toBe("[0,100,101,-100,-101]");
96
+ expect(JSON.stringify<u64[]>([0, 100, 101])).toBe("[0,100,101]");
161
97
 
162
- expect(
163
- JSON.stringify<i64[]>([0, 100, 101, -100, -101])
164
- ).toBe("[0,100,101,-100,-101]");
98
+ expect(JSON.stringify<i32[]>([0, 100, 101, -100, -101])).toBe(
99
+ "[0,100,101,-100,-101]",
100
+ );
165
101
 
102
+ expect(JSON.stringify<i64[]>([0, 100, 101, -100, -101])).toBe(
103
+ "[0,100,101,-100,-101]",
104
+ );
166
105
  });
167
106
 
168
107
  describe("Should serialize float arrays", () => {
169
-
170
108
  expect(
171
- JSON.stringify<f64[]>([7.23, 10e2, 10e2, 123456e-5, 123456e-5, 0.0, 7.23])
109
+ JSON.stringify<f64[]>([7.23, 10e2, 10e2, 123456e-5, 123456e-5, 0.0, 7.23]),
172
110
  ).toBe("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]");
173
111
 
174
- expect(
175
- JSON.stringify<f64[]>([1e21, 1e22, 1e-7, 1e-8, 1e-9])
176
- ).toBe("[1e+21,1e+22,1e-7,1e-8,1e-9]");
177
-
112
+ expect(JSON.stringify<f64[]>([1e21, 1e22, 1e-7, 1e-8, 1e-9])).toBe(
113
+ "[1e+21,1e+22,1e-7,1e-8,1e-9]",
114
+ );
178
115
  });
179
116
 
180
117
  describe("Should serialize boolean arrays", () => {
118
+ expect(JSON.stringify<bool[]>([true, false])).toBe("[true,false]");
181
119
 
182
- expect(
183
- JSON.stringify<bool[]>([true, false])
184
- ).toBe("[true,false]");
185
-
186
- expect(
187
- JSON.stringify<boolean[]>([true, false])
188
- ).toBe("[true,false]");
189
-
120
+ expect(JSON.stringify<boolean[]>([true, false])).toBe("[true,false]");
190
121
  });
191
122
 
192
123
  describe("Should serialize string arrays", () => {
193
-
194
124
  expect(
195
- JSON.stringify<string[]>(['string \"with random spa\nces and \nnewlines\n\n\n'])
125
+ JSON.stringify<string[]>([
126
+ 'string "with random spa\nces and \nnewlines\n\n\n',
127
+ ]),
196
128
  ).toBe('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]');
197
-
198
129
  });
199
130
 
200
131
  describe("Should serialize nested integer arrays", () => {
201
-
202
- expect(
203
- JSON.stringify<i64[][]>([[100, 101], [-100, -101], [0]])
204
- ).toBe("[[100,101],[-100,-101],[0]]");
205
-
132
+ expect(JSON.stringify<i64[][]>([[100, 101], [-100, -101], [0]])).toBe(
133
+ "[[100,101],[-100,-101],[0]]",
134
+ );
206
135
  });
207
136
 
208
137
  describe("Should serialize nested float arrays", () => {
209
-
210
138
  expect(
211
139
  JSON.stringify<f64[][]>([
212
140
  [7.23],
@@ -216,25 +144,19 @@ describe("Should serialize nested float arrays", () => {
216
144
  [123456e-5],
217
145
  [0.0],
218
146
  [7.23],
219
- ])
147
+ ]),
220
148
  ).toBe("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]");
221
-
222
149
  });
223
150
 
224
151
  describe("Should serialize nested boolean arrays", () => {
152
+ expect(JSON.stringify<bool[][]>([[true], [false]])).toBe("[[true],[false]]");
225
153
 
226
- expect(
227
- JSON.stringify<bool[][]>([[true], [false]])
228
- ).toBe("[[true],[false]]");
229
-
230
- expect(
231
- JSON.stringify<boolean[][]>([[true], [false]])
232
- ).toBe("[[true],[false]]");
233
-
154
+ expect(JSON.stringify<boolean[][]>([[true], [false]])).toBe(
155
+ "[[true],[false]]",
156
+ );
234
157
  });
235
158
 
236
159
  describe("Should serialize object arrays", () => {
237
-
238
160
  expect(
239
161
  JSON.stringify<Vec3[]>([
240
162
  {
@@ -247,19 +169,17 @@ describe("Should serialize object arrays", () => {
247
169
  y: -2.1,
248
170
  z: 9.3,
249
171
  },
250
- ])
172
+ ]),
251
173
  ).toBe('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]');
252
-
253
174
  });
254
175
 
255
176
  describe("Should serialize objects", () => {
256
-
257
177
  expect(
258
178
  JSON.stringify<Vec3>({
259
179
  x: 3.4,
260
180
  y: 1.2,
261
181
  z: 8.3,
262
- })
182
+ }),
263
183
  ).toBe('{"x":3.4,"y":1.2,"z":8.3}');
264
184
 
265
185
  expect(
@@ -274,144 +194,102 @@ describe("Should serialize objects", () => {
274
194
  z: 8.3,
275
195
  },
276
196
  isVerified: true,
277
- })
278
- ).toBe('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}');
197
+ }),
198
+ ).toBe(
199
+ '{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}',
200
+ );
279
201
 
280
- expect(
281
- JSON.stringify<ObjectWithFloat>({ f: 7.23 })
282
- ).toBe('{"f":7.23}');
202
+ expect(JSON.stringify<ObjectWithFloat>({ f: 7.23 })).toBe('{"f":7.23}');
283
203
 
284
- expect(
285
- JSON.stringify<ObjectWithFloat>({ f: 0.000001 })
286
- ).toBe('{"f":0.000001}');
204
+ expect(JSON.stringify<ObjectWithFloat>({ f: 0.000001 })).toBe(
205
+ '{"f":0.000001}',
206
+ );
287
207
 
288
- expect(
289
- JSON.stringify<ObjectWithFloat>({ f: 1e-7 })
290
- ).toBe('{"f":1e-7}');
208
+ expect(JSON.stringify<ObjectWithFloat>({ f: 1e-7 })).toBe('{"f":1e-7}');
291
209
 
292
- expect(
293
- JSON.stringify<ObjectWithFloat>({ f: 1e20 })
294
- ).toBe('{"f":100000000000000000000.0}');
210
+ expect(JSON.stringify<ObjectWithFloat>({ f: 1e20 })).toBe(
211
+ '{"f":100000000000000000000.0}',
212
+ );
295
213
 
296
- expect(
297
- JSON.stringify<ObjectWithFloat>({ f: 1e21 })
298
- ).toBe('{"f":1e+21}');
299
-
300
- expect(
301
- JSON.stringify<ObjWithStrangeKey<string>>({ data: "foo" })
302
- ).toBe('{"a\\\\\\t\\"\\u0002b`c":"foo"}');
214
+ expect(JSON.stringify<ObjectWithFloat>({ f: 1e21 })).toBe('{"f":1e+21}');
303
215
 
216
+ expect(JSON.stringify<ObjWithStrangeKey<string>>({ data: "foo" })).toBe(
217
+ '{"a\\\\\\t\\"\\u0002b`c":"foo"}',
218
+ );
304
219
  });
305
220
 
306
221
  describe("Should serialize @omit'ed objects", () => {
307
-
308
222
  expect(
309
223
  JSON.stringify(<OmitIf>{
310
- y: 1
311
- })
224
+ y: 1,
225
+ }),
312
226
  ).toBe('{"x":1,"y":1,"z":1}');
313
-
314
227
  });
315
228
 
316
229
  describe("Should deserialize strings", () => {
230
+ expect(JSON.parse<string>('"abcdefg"')).toBe("abcdefg");
317
231
 
318
232
  expect(
319
- JSON.parse<string>("\"abcdefg\"")
320
- ).toBe("abcdefg");
321
-
322
- expect(
323
- JSON.parse<string>('"\\"st\\\\\\"ring\\\\\\" w\\\\\\"\\\\\\"ith quotes\\\\\\"\\\""')
233
+ JSON.parse<string>(
234
+ '"\\"st\\\\\\"ring\\\\\\" w\\\\\\"\\\\\\"ith quotes\\\\\\"\\""',
235
+ ),
324
236
  ).toBe('"st\\"ring\\" w\\"\\"ith quotes\\""');
325
237
 
326
238
  expect(
327
- JSON.parse<string>('"\\"string \\\\\\"with random spa\\\\nces and \\\\nnewlines\\\\n\\\\n\\\\n\\""')
239
+ JSON.parse<string>(
240
+ '"\\"string \\\\\\"with random spa\\\\nces and \\\\nnewlines\\\\n\\\\n\\\\n\\""',
241
+ ),
328
242
  ).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
329
243
 
330
244
  expect(
331
- JSON.parse<string>('"\\"string with colon : comma , brace [ ] bracket { } and quote \\\\\\" and other quote \\\\\\\\\\"\\\""')
332
- ).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\""');
333
-
245
+ JSON.parse<string>(
246
+ '"\\"string with colon : comma , brace [ ] bracket { } and quote \\\\\\" and other quote \\\\\\\\\\"\\""',
247
+ ),
248
+ ).toBe(
249
+ '"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\""',
250
+ );
334
251
  });
335
252
 
336
253
  describe("Should deserialize integers", () => {
254
+ expect(JSON.parse<i32>("0")).toBe(<i32>0);
337
255
 
338
- expect(
339
- JSON.parse<i32>("0")
340
- ).toBe(<i32>0);
341
-
342
- expect(
343
- JSON.parse<u32>("100")
344
- ).toBe(<u32>100);
256
+ expect(JSON.parse<u32>("100")).toBe(<u32>100);
345
257
 
346
- expect(
347
- JSON.parse<u64>("101")
348
- ).toBe(<u64>101);
258
+ expect(JSON.parse<u64>("101")).toBe(<u64>101);
349
259
 
350
- expect(
351
- JSON.parse<i32>("-100")
352
- ).toBe(<i32>-100);
353
-
354
- expect(
355
- JSON.parse<i64>("-101")
356
- ).toBe(<i64>-101);
260
+ expect(JSON.parse<i32>("-100")).toBe(<i32>-100);
357
261
 
262
+ expect(JSON.parse<i64>("-101")).toBe(<i64>-101);
358
263
  });
359
264
 
360
265
  describe("Should deserialize floats", () => {
266
+ expect(JSON.parse<f64>("7.23")).toBe(7.23);
361
267
 
362
- expect(
363
- JSON.parse<f64>("7.23")
364
- ).toBe(7.23);
268
+ expect(JSON.parse<f64>("1000.0")).toBe(1000.0);
365
269
 
366
- expect(
367
- JSON.parse<f64>("1000.0")
368
- ).toBe(1000.0);
270
+ expect(JSON.parse<f64>("1.23456")).toBe(1.23456);
369
271
 
370
- expect(
371
- JSON.parse<f64>("1.23456")
372
- ).toBe(1.23456);
272
+ expect(JSON.parse<f64>("0.0")).toBe(0.0);
373
273
 
374
- expect(
375
- JSON.parse<f64>("0.0")
376
- ).toBe(0.0);
274
+ expect(JSON.parse<f64>("-7.23")).toBe(-7.23);
377
275
 
378
- expect(
379
- JSON.parse<f64>("-7.23")
380
- ).toBe(-7.23);
276
+ expect(JSON.parse<f64>("0.000001")).toBe(0.000001);
381
277
 
382
- expect(
383
- JSON.parse<f64>("0.000001")
384
- ).toBe(0.000001);
278
+ expect(JSON.parse<f64>("1e-7")).toBe(1e-7);
385
279
 
386
- expect(
387
- JSON.parse<f64>("1e-7")
388
- ).toBe(1e-7);
389
-
390
- expect(
391
- JSON.parse<f64>("100000000000000000000.0")
392
- ).toBe(1e20);
393
-
394
- expect(
395
- JSON.parse<f64>("1e+21")
396
- ).toBe(1e21);
280
+ expect(JSON.parse<f64>("100000000000000000000.0")).toBe(1e20);
397
281
 
282
+ expect(JSON.parse<f64>("1e+21")).toBe(1e21);
398
283
  });
399
284
 
400
285
  describe("Should deserialize booleans", () => {
286
+ expect(JSON.parse<boolean>("true")).toBe(true);
401
287
 
402
- expect(
403
- JSON.parse<boolean>("true")
404
- ).toBe(true);
405
-
406
- expect(
407
- JSON.parse<boolean>("false")
408
- ).toBe(false);
409
-
288
+ expect(JSON.parse<boolean>("false")).toBe(false);
410
289
  });
411
290
 
412
291
  describe("Should deserialize class inheritance", () => {
413
-
414
- const jsonStr = "{\"a\":\"1\",\"b\":\"2\"}";
292
+ const jsonStr = '{"a":"1","b":"2"}';
415
293
  const obj = JSON.parse<DerivedObject>(jsonStr);
416
294
 
417
295
  expect(obj instanceof DerivedObject).toBe(true);
@@ -420,119 +298,131 @@ describe("Should deserialize class inheritance", () => {
420
298
  });
421
299
 
422
300
  describe("Should deserialize nulls", () => {
423
-
424
- expect(
425
- JSON.stringify(JSON.parse<Null>("null"))
426
- ).toBe("null");
427
-
301
+ expect(JSON.stringify(JSON.parse<Null>("null"))).toBe("null");
428
302
  });
429
303
 
430
304
  describe("Should deserialize integer arrays", () => {
305
+ expect(JSON.stringify(JSON.parse<u32[]>("[0,100,101]"))).toBe(
306
+ JSON.stringify([0, 100, 101]),
307
+ );
431
308
 
432
- expect(
433
- JSON.stringify(JSON.parse<u32[]>("[0,100,101]"))
434
- ).toBe(JSON.stringify([0, 100, 101]));
435
-
436
- expect(
437
- JSON.stringify(JSON.parse<i32[]>("[0,100,101,-100,-101]"))
438
- ).toBe(JSON.stringify([0, 100, 101, -100, -101]));
439
-
309
+ expect(JSON.stringify(JSON.parse<i32[]>("[0,100,101,-100,-101]"))).toBe(
310
+ JSON.stringify([0, 100, 101, -100, -101]),
311
+ );
440
312
  });
441
313
 
442
314
  describe("Should deserialize float arrays", () => {
443
-
444
315
  expect(
445
- JSON.stringify(JSON.parse<f64[]>("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]"))
316
+ JSON.stringify(
317
+ JSON.parse<f64[]>("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]"),
318
+ ),
446
319
  ).toBe(JSON.stringify([7.23, 1000.0, 1000.0, 1.23456, 1.23456, 0.0, 7.23]));
447
320
 
448
321
  expect(
449
- JSON.stringify(JSON.parse<f64[]>("[1e+21,1e+22,1e-7,1e-8,1e-9]"))
322
+ JSON.stringify(JSON.parse<f64[]>("[1e+21,1e+22,1e-7,1e-8,1e-9]")),
450
323
  ).toBe(JSON.stringify([1e21, 1e22, 1e-7, 1e-8, 1e-9]));
451
-
452
324
  });
453
325
 
454
326
  describe("Should deserialize boolean arrays", () => {
455
-
456
- expect(
457
- JSON.stringify(JSON.parse<boolean[]>("[true,false]"))
458
- ).toBe(JSON.stringify([true, false]));
459
-
327
+ expect(JSON.stringify(JSON.parse<boolean[]>("[true,false]"))).toBe(
328
+ JSON.stringify([true, false]),
329
+ );
460
330
  });
461
331
 
462
332
  describe("Should deserialize string arrays", () => {
463
-
464
333
  expect(
465
- JSON.stringify(JSON.parse<string[]>('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]'))
466
- ).toBe(JSON.stringify([ 'string "with random spa\nces and \nnewlines\n\n\n' ]));
467
-
334
+ JSON.stringify(
335
+ JSON.parse<string[]>(
336
+ '["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]',
337
+ ),
338
+ ),
339
+ ).toBe(JSON.stringify(['string "with random spa\nces and \nnewlines\n\n\n']));
468
340
  });
469
341
 
470
342
  describe("Should deserialize nested integer arrays", () => {
471
-
472
343
  expect(
473
- JSON.stringify(JSON.parse<i64[][]>("[[100,101],[-100,-101],[0]]"))
344
+ JSON.stringify(JSON.parse<i64[][]>("[[100,101],[-100,-101],[0]]")),
474
345
  ).toBe(JSON.stringify([[100, 101], [-100, -101], [0]]));
475
-
476
346
  });
477
347
 
478
348
  describe("Should deserialize nested float arrays", () => {
479
-
480
349
  expect(
481
- JSON.stringify(JSON.parse<f64[][]>("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]"))
482
- ).toBe(JSON.stringify([[7.23], [1000.0], [1000.0], [1.23456], [1.23456], [0.0], [7.23]]));
483
-
350
+ JSON.stringify(
351
+ JSON.parse<f64[][]>(
352
+ "[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]",
353
+ ),
354
+ ),
355
+ ).toBe(
356
+ JSON.stringify([
357
+ [7.23],
358
+ [1000.0],
359
+ [1000.0],
360
+ [1.23456],
361
+ [1.23456],
362
+ [0.0],
363
+ [7.23],
364
+ ]),
365
+ );
484
366
  });
485
367
 
486
368
  describe("Should deserialize nested boolean arrays", () => {
487
-
488
- expect(
489
- JSON.stringify(JSON.parse<boolean[][]>("[[true],[false]]"))
490
- ).toBe(JSON.stringify([[true], [false]]));
491
-
369
+ expect(JSON.stringify(JSON.parse<boolean[][]>("[[true],[false]]"))).toBe(
370
+ JSON.stringify([[true], [false]]),
371
+ );
492
372
  });
493
373
 
494
374
  describe("Should deserialize object arrays", () => {
495
-
496
375
  expect(
497
- JSON.stringify(JSON.parse<Vec3[]>('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]'))
498
- ).toBe(JSON.stringify(<Vec3[]>[
499
- { x: 3.4, y: 1.2, z: 8.3 },
500
- { x: 3.4, y: -2.1, z: 9.3 }
501
- ]));
502
-
376
+ JSON.stringify(
377
+ JSON.parse<Vec3[]>(
378
+ '[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]',
379
+ ),
380
+ ),
381
+ ).toBe(
382
+ JSON.stringify(<Vec3[]>[
383
+ { x: 3.4, y: 1.2, z: 8.3 },
384
+ { x: 3.4, y: -2.1, z: 9.3 },
385
+ ]),
386
+ );
503
387
  });
504
388
 
505
389
  describe("Should deserialize Objects", () => {
390
+ expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))).toBe(
391
+ JSON.stringify(<Vec3>{ x: 3.4, y: 1.2, z: 8.3 }),
392
+ );
393
+
394
+ expect(
395
+ JSON.stringify(
396
+ JSON.parse<Player>(
397
+ '{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}',
398
+ ),
399
+ ),
400
+ ).toBe(
401
+ JSON.stringify(<Player>{
402
+ firstName: "Emmet",
403
+ lastName: "West",
404
+ lastActive: [8, 27, 2022],
405
+ age: 23,
406
+ pos: { x: 3.4, y: 1.2, z: 8.3 },
407
+ isVerified: true,
408
+ }),
409
+ );
506
410
 
507
- expect(
508
- JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))
509
- ).toBe(JSON.stringify(<Vec3>{ x: 3.4, y: 1.2, z: 8.3 }));
510
-
511
- expect(
512
- JSON.stringify(JSON.parse<Player>('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}'))
513
- ).toBe(JSON.stringify(<Player>{
514
- firstName: "Emmet",
515
- lastName: "West",
516
- lastActive: [8, 27, 2022],
517
- age: 23,
518
- pos: { x: 3.4, y: 1.2, z: 8.3 },
519
- isVerified: true
520
- }));
521
-
522
- expect(
523
- JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":7.23}'))
524
- ).toBe(JSON.stringify(<ObjectWithFloat>{ f: 7.23 }));
411
+ expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":7.23}'))).toBe(
412
+ JSON.stringify(<ObjectWithFloat>{ f: 7.23 }),
413
+ );
525
414
 
526
- expect(
527
- JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":0.000001}'))
528
- ).toBe(JSON.stringify(<ObjectWithFloat>{ f: 0.000001 }));
415
+ expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":0.000001}'))).toBe(
416
+ JSON.stringify(<ObjectWithFloat>{ f: 0.000001 }),
417
+ );
529
418
 
530
419
  expect(
531
- JSON.stringify(JSON.parse<ObjWithStrangeKey<string>>('{"a\\\\\\t\\"\\u0002b`c":"foo"}'))
420
+ JSON.stringify(
421
+ JSON.parse<ObjWithStrangeKey<string>>('{"a\\\\\\t\\"\\u0002b`c":"foo"}'),
422
+ ),
532
423
  ).toBe(JSON.stringify(<ObjWithStrangeKey<string>>{ data: "foo" }));
533
-
534
424
  });
535
425
 
536
426
  run({
537
- log: true
538
- });
427
+ log: true,
428
+ });