fast-json-stringify 6.0.0 → 6.0.1
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.
- package/.github/dependabot.yml +1 -1
- package/.github/workflows/benchmark.yml +3 -3
- package/.github/workflows/ci.yml +1 -1
- package/README.md +15 -15
- package/benchmark/bench-cmp-lib.js +0 -1
- package/eslint.config.js +9 -0
- package/index.js +4 -8
- package/lib/serializer.js +1 -2
- package/lib/validator.js +1 -1
- package/package.json +40 -16
- package/test/additionalProperties.test.js +20 -20
- package/test/allof.test.js +36 -40
- package/test/any.test.js +28 -28
- package/test/anyof.test.js +44 -46
- package/test/array.test.js +19 -19
- package/test/asNumber.test.js +2 -2
- package/test/basic.test.js +20 -32
- package/test/bigint.test.js +6 -6
- package/test/clean-cache.test.js +9 -7
- package/test/const.test.js +35 -35
- package/test/date.test.js +77 -77
- package/test/debug-mode.test.js +27 -27
- package/test/defaults.test.js +2 -2
- package/test/enum.test.js +3 -3
- package/test/fix-604.test.js +18 -17
- package/test/if-then-else.test.js +22 -24
- package/test/inferType.test.js +4 -4
- package/test/infinity.test.js +4 -4
- package/test/integer.test.js +21 -21
- package/test/invalidSchema.test.js +4 -8
- package/test/issue-479.test.js +2 -2
- package/test/json-schema-test-suite/draft4.test.js +3 -3
- package/test/json-schema-test-suite/draft6.test.js +3 -3
- package/test/json-schema-test-suite/draft7.test.js +3 -3
- package/test/json-schema-test-suite/util.js +6 -9
- package/test/missing-values.test.js +8 -8
- package/test/multi-type-serializer.test.js +2 -2
- package/test/nestedObjects.test.js +3 -3
- package/test/nullable.test.js +35 -35
- package/test/oneof.test.js +27 -29
- package/test/patternProperties.test.js +11 -11
- package/test/recursion.test.js +6 -6
- package/test/ref.test.js +102 -186
- package/test/regex.test.js +4 -5
- package/test/required.test.js +42 -77
- package/test/requiresAjv.test.js +34 -32
- package/test/sanitize.test.js +40 -41
- package/test/sanitize2.test.js +11 -11
- package/test/sanitize3.test.js +13 -11
- package/test/sanitize4.test.js +10 -8
- package/test/sanitize5.test.js +11 -11
- package/test/sanitize6.test.js +14 -14
- package/test/sanitize7.test.js +5 -5
- package/test/side-effect.test.js +12 -12
- package/test/standalone-mode.test.js +29 -26
- package/test/string.test.js +12 -12
- package/test/surrogate.test.js +9 -9
- package/test/toJSON.test.js +9 -9
- package/test/typebox.test.js +2 -2
- package/test/typesArray.test.js +34 -34
- package/test/unknownFormats.test.js +5 -5
- package/test/webpack.test.js +2 -2
- package/types/index.d.ts +29 -29
- package/types/index.test-d.ts +75 -74
- package/.taprc +0 -7
package/test/array.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const validator = require('is-my-json-valid')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
const Ajv = require('ajv')
|
|
@@ -8,7 +8,7 @@ const Ajv = require('ajv')
|
|
|
8
8
|
test('error on invalid largeArrayMechanism', (t) => {
|
|
9
9
|
t.plan(1)
|
|
10
10
|
|
|
11
|
-
t.throws(() => build({
|
|
11
|
+
t.assert.throws(() => build({
|
|
12
12
|
title: 'large array of null values with default mechanism',
|
|
13
13
|
type: 'object',
|
|
14
14
|
properties: {
|
|
@@ -31,9 +31,9 @@ function buildTest (schema, toStringify, options) {
|
|
|
31
31
|
const stringify = build(schema, options)
|
|
32
32
|
const output = stringify(toStringify)
|
|
33
33
|
|
|
34
|
-
t.
|
|
35
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
36
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
34
|
+
t.assert.deepStrictEqual(JSON.parse(output), JSON.parse(JSON.stringify(toStringify)))
|
|
35
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
36
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -216,7 +216,7 @@ test('invalid items throw', (t) => {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
const stringify = build(schema)
|
|
219
|
-
t.throws(() => stringify({ args: ['invalid'] }))
|
|
219
|
+
t.assert.throws(() => stringify({ args: ['invalid'] }))
|
|
220
220
|
})
|
|
221
221
|
|
|
222
222
|
buildTest({
|
|
@@ -258,7 +258,7 @@ test('array items is a list of schema and additionalItems is true, just the desc
|
|
|
258
258
|
]
|
|
259
259
|
})
|
|
260
260
|
|
|
261
|
-
t.equal(result, '{"foo":["foo","bar",1]}')
|
|
261
|
+
t.assert.equal(result, '{"foo":["foo","bar",1]}')
|
|
262
262
|
})
|
|
263
263
|
|
|
264
264
|
test('array items is a list of schema and additionalItems is true, just the described item is validated', (t) => {
|
|
@@ -287,7 +287,7 @@ test('array items is a list of schema and additionalItems is true, just the desc
|
|
|
287
287
|
foo: ['foo']
|
|
288
288
|
})
|
|
289
289
|
|
|
290
|
-
t.equal(result, '{"foo":["foo"]}')
|
|
290
|
+
t.assert.equal(result, '{"foo":["foo"]}')
|
|
291
291
|
})
|
|
292
292
|
|
|
293
293
|
test('array items is a list of schema and additionalItems is false /1', (t) => {
|
|
@@ -307,7 +307,7 @@ test('array items is a list of schema and additionalItems is false /1', (t) => {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
const stringify = build(schema)
|
|
310
|
-
t.throws(() => stringify({ foo: ['foo', 'bar'] }), new Error('Item at 1 does not match schema definition.'))
|
|
310
|
+
t.assert.throws(() => stringify({ foo: ['foo', 'bar'] }), new Error('Item at 1 does not match schema definition.'))
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
test('array items is a list of schema and additionalItems is false /2', (t) => {
|
|
@@ -329,9 +329,9 @@ test('array items is a list of schema and additionalItems is false /2', (t) => {
|
|
|
329
329
|
|
|
330
330
|
const stringify = build(schema)
|
|
331
331
|
|
|
332
|
-
t.throws(() => stringify({ foo: [1, 'bar'] }), new Error('Item at 0 does not match schema definition.'))
|
|
333
|
-
t.throws(() => stringify({ foo: ['foo', 1] }), new Error('Item at 1 does not match schema definition.'))
|
|
334
|
-
t.throws(() => stringify({ foo: ['foo', 'bar', 'baz'] }), new Error('Item at 2 does not match schema definition.'))
|
|
332
|
+
t.assert.throws(() => stringify({ foo: [1, 'bar'] }), new Error('Item at 0 does not match schema definition.'))
|
|
333
|
+
t.assert.throws(() => stringify({ foo: ['foo', 1] }), new Error('Item at 1 does not match schema definition.'))
|
|
334
|
+
t.assert.throws(() => stringify({ foo: ['foo', 'bar', 'baz'] }), new Error('Item at 2 does not match schema definition.'))
|
|
335
335
|
})
|
|
336
336
|
|
|
337
337
|
test('array items is a schema and additionalItems is false', (t) => {
|
|
@@ -354,8 +354,8 @@ test('array items is a schema and additionalItems is false', (t) => {
|
|
|
354
354
|
const ajv = new Ajv({ allErrors: true, strict: false })
|
|
355
355
|
|
|
356
356
|
const validate = ajv.compile(schema)
|
|
357
|
-
t.
|
|
358
|
-
t.equal(validate({ foo: ['foo', 'bar'] }), true)
|
|
357
|
+
t.assert.equal(stringify({ foo: ['foo', 'bar'] }), '{"foo":["foo","bar"]}')
|
|
358
|
+
t.assert.equal(validate({ foo: ['foo', 'bar'] }), true)
|
|
359
359
|
})
|
|
360
360
|
|
|
361
361
|
// https://github.com/fastify/fast-json-stringify/issues/279
|
|
@@ -402,7 +402,7 @@ test('object array with anyOf and symbol', (t) => {
|
|
|
402
402
|
{ name: 'name-0', option: 'Foo' },
|
|
403
403
|
{ name: 'name-1', option: 'Bar' }
|
|
404
404
|
])
|
|
405
|
-
t.equal(value, '[{"name":"name-0","option":"Foo"},{"name":"name-1","option":"Bar"}]')
|
|
405
|
+
t.assert.equal(value, '[{"name":"name-0","option":"Foo"},{"name":"name-1","option":"Bar"}]')
|
|
406
406
|
})
|
|
407
407
|
|
|
408
408
|
test('different arrays with same item schemas', (t) => {
|
|
@@ -427,7 +427,7 @@ test('different arrays with same item schemas', (t) => {
|
|
|
427
427
|
const stringify = build(schema)
|
|
428
428
|
const data = { array1: ['bar'], array2: ['foo', 'bar'] }
|
|
429
429
|
|
|
430
|
-
t.equal(stringify(data), '{"array1":["bar"],"array2":["foo","bar"]}')
|
|
430
|
+
t.assert.equal(stringify(data), '{"array1":["bar"],"array2":["foo","bar"]}')
|
|
431
431
|
})
|
|
432
432
|
|
|
433
433
|
const largeArray = new Array(2e4).fill({ a: 'test', b: 1 })
|
|
@@ -557,7 +557,7 @@ buildTest({
|
|
|
557
557
|
test('error on invalid value for largeArraySize /1', (t) => {
|
|
558
558
|
t.plan(1)
|
|
559
559
|
|
|
560
|
-
t.throws(() => build({
|
|
560
|
+
t.assert.throws(() => build({
|
|
561
561
|
title: 'large array of null values with default mechanism',
|
|
562
562
|
type: 'object',
|
|
563
563
|
properties: {
|
|
@@ -574,7 +574,7 @@ test('error on invalid value for largeArraySize /1', (t) => {
|
|
|
574
574
|
test('error on invalid value for largeArraySize /2', (t) => {
|
|
575
575
|
t.plan(1)
|
|
576
576
|
|
|
577
|
-
t.throws(() => build({
|
|
577
|
+
t.assert.throws(() => build({
|
|
578
578
|
title: 'large array of null values with default mechanism',
|
|
579
579
|
type: 'object',
|
|
580
580
|
properties: {
|
|
@@ -591,7 +591,7 @@ test('error on invalid value for largeArraySize /2', (t) => {
|
|
|
591
591
|
test('error on invalid value for largeArraySize /3', (t) => {
|
|
592
592
|
t.plan(1)
|
|
593
593
|
|
|
594
|
-
t.throws(() => build({
|
|
594
|
+
t.assert.throws(() => build({
|
|
595
595
|
title: 'large array of null values with default mechanism',
|
|
596
596
|
type: 'object',
|
|
597
597
|
properties: {
|
package/test/asNumber.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
|
|
5
5
|
test('asNumber should convert BigInt', (t) => {
|
|
6
6
|
t.plan(1)
|
|
@@ -9,5 +9,5 @@ test('asNumber should convert BigInt', (t) => {
|
|
|
9
9
|
|
|
10
10
|
const number = serializer.asNumber(11753021440n)
|
|
11
11
|
|
|
12
|
-
t.equal(number, '11753021440')
|
|
12
|
+
t.assert.equal(number, '11753021440')
|
|
13
13
|
})
|
package/test/basic.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const validator = require('is-my-json-valid')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
@@ -12,9 +12,9 @@ function buildTest (schema, toStringify) {
|
|
|
12
12
|
const stringify = build(schema)
|
|
13
13
|
const output = stringify(toStringify)
|
|
14
14
|
|
|
15
|
-
t.
|
|
16
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
17
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
15
|
+
t.assert.deepStrictEqual(JSON.parse(output), toStringify)
|
|
16
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
17
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -281,41 +281,34 @@ test('throw an error or coerce numbers and integers that are not numbers', (t) =
|
|
|
281
281
|
}
|
|
282
282
|
})
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
t.assert.throws(() => {
|
|
285
285
|
stringify({ age: 'hello ', distance: 'long' })
|
|
286
|
-
|
|
287
|
-
} catch (err) {
|
|
288
|
-
t.ok(err)
|
|
289
|
-
}
|
|
286
|
+
}, { message: 'The value "hello " cannot be converted to a number.' })
|
|
290
287
|
|
|
291
288
|
const result = stringify({
|
|
292
289
|
age: '42',
|
|
293
290
|
distance: true
|
|
294
291
|
})
|
|
295
292
|
|
|
296
|
-
t.
|
|
297
|
-
t.end()
|
|
293
|
+
t.assert.deepStrictEqual(JSON.parse(result), { age: 42, distance: 1 })
|
|
298
294
|
})
|
|
299
295
|
|
|
300
296
|
test('Should throw on invalid schema', t => {
|
|
301
297
|
t.plan(1)
|
|
302
|
-
|
|
298
|
+
t.assert.throws(() => {
|
|
303
299
|
build({
|
|
304
300
|
type: 'Dinosaur',
|
|
305
301
|
properties: {
|
|
306
302
|
claws: { type: 'sharp' }
|
|
307
303
|
}
|
|
308
304
|
})
|
|
309
|
-
|
|
310
|
-
} catch (err) {
|
|
311
|
-
t.ok(err)
|
|
312
|
-
}
|
|
305
|
+
}, { message: 'schema is invalid: data/properties/claws/type must be equal to one of the allowed values' })
|
|
313
306
|
})
|
|
314
307
|
|
|
315
308
|
test('additionalProperties - throw on unknown type', (t) => {
|
|
316
309
|
t.plan(1)
|
|
317
310
|
|
|
318
|
-
|
|
311
|
+
t.assert.throws(() => {
|
|
319
312
|
build({
|
|
320
313
|
title: 'check array coerce',
|
|
321
314
|
type: 'object',
|
|
@@ -325,15 +318,13 @@ test('additionalProperties - throw on unknown type', (t) => {
|
|
|
325
318
|
}
|
|
326
319
|
})
|
|
327
320
|
t.fail('should be an invalid schema')
|
|
328
|
-
}
|
|
329
|
-
t.ok(err)
|
|
330
|
-
}
|
|
321
|
+
}, { message: 'schema is invalid: data/additionalProperties/type must be equal to one of the allowed values' })
|
|
331
322
|
})
|
|
332
323
|
|
|
333
324
|
test('patternProperties - throw on unknown type', (t) => {
|
|
334
325
|
t.plan(1)
|
|
335
326
|
|
|
336
|
-
|
|
327
|
+
t.assert.throws(() => {
|
|
337
328
|
build({
|
|
338
329
|
title: 'check array coerce',
|
|
339
330
|
type: 'object',
|
|
@@ -344,10 +335,7 @@ test('patternProperties - throw on unknown type', (t) => {
|
|
|
344
335
|
}
|
|
345
336
|
}
|
|
346
337
|
})
|
|
347
|
-
|
|
348
|
-
} catch (err) {
|
|
349
|
-
t.ok(err)
|
|
350
|
-
}
|
|
338
|
+
}, { message: 'schema is invalid: data/patternProperties/foo/type must be equal to one of the allowed values' })
|
|
351
339
|
})
|
|
352
340
|
|
|
353
341
|
test('render a double quote as JSON /1', (t) => {
|
|
@@ -362,8 +350,8 @@ test('render a double quote as JSON /1', (t) => {
|
|
|
362
350
|
const stringify = build(schema)
|
|
363
351
|
const output = stringify(toStringify)
|
|
364
352
|
|
|
365
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
366
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
353
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
354
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
367
355
|
})
|
|
368
356
|
|
|
369
357
|
test('render a double quote as JSON /2', (t) => {
|
|
@@ -378,8 +366,8 @@ test('render a double quote as JSON /2', (t) => {
|
|
|
378
366
|
const stringify = build(schema)
|
|
379
367
|
const output = stringify(toStringify)
|
|
380
368
|
|
|
381
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
382
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
369
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
370
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
383
371
|
})
|
|
384
372
|
|
|
385
373
|
test('render a long string', (t) => {
|
|
@@ -394,8 +382,8 @@ test('render a long string', (t) => {
|
|
|
394
382
|
const stringify = build(schema)
|
|
395
383
|
const output = stringify(toStringify)
|
|
396
384
|
|
|
397
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
398
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
385
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
386
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
399
387
|
})
|
|
400
388
|
|
|
401
389
|
test('returns JSON.stringify if schema type is boolean', t => {
|
|
@@ -408,5 +396,5 @@ test('returns JSON.stringify if schema type is boolean', t => {
|
|
|
408
396
|
|
|
409
397
|
const array = [1, true, 'test']
|
|
410
398
|
const stringify = build(schema)
|
|
411
|
-
t.equal(stringify(array), JSON.stringify(array))
|
|
399
|
+
t.assert.equal(stringify(array), JSON.stringify(array))
|
|
412
400
|
})
|
package/test/bigint.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
7
7
|
test('render a bigint as JSON', (t) => {
|
|
@@ -15,7 +15,7 @@ test('render a bigint as JSON', (t) => {
|
|
|
15
15
|
const stringify = build(schema)
|
|
16
16
|
const output = stringify(1615n)
|
|
17
17
|
|
|
18
|
-
t.equal(output, '1615')
|
|
18
|
+
t.assert.equal(output, '1615')
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
test('render an object with a bigint as JSON', (t) => {
|
|
@@ -36,7 +36,7 @@ test('render an object with a bigint as JSON', (t) => {
|
|
|
36
36
|
id: 1615n
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
t.equal(output, '{"id":1615}')
|
|
39
|
+
t.assert.equal(output, '{"id":1615}')
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
test('render an array with a bigint as JSON', (t) => {
|
|
@@ -53,7 +53,7 @@ test('render an array with a bigint as JSON', (t) => {
|
|
|
53
53
|
const stringify = build(schema)
|
|
54
54
|
const output = stringify([1615n])
|
|
55
55
|
|
|
56
|
-
t.equal(output, '[1615]')
|
|
56
|
+
t.assert.equal(output, '[1615]')
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
test('render an object with an additionalProperty of type bigint as JSON', (t) => {
|
|
@@ -72,5 +72,5 @@ test('render an object with an additionalProperty of type bigint as JSON', (t) =
|
|
|
72
72
|
num: 1615n
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
t.equal(output, '{"num":1615}')
|
|
75
|
+
t.assert.equal(output, '{"num":1615}')
|
|
76
76
|
})
|
package/test/clean-cache.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
test('Should clean the cache', (t) => {
|
|
@@ -11,9 +11,10 @@ test('Should clean the cache', (t) => {
|
|
|
11
11
|
type: 'string'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
t.assert.doesNotThrow(() => {
|
|
15
|
+
build(schema)
|
|
16
|
+
build(schema)
|
|
17
|
+
})
|
|
17
18
|
})
|
|
18
19
|
|
|
19
20
|
test('Should clean the cache with external schemas', (t) => {
|
|
@@ -39,7 +40,8 @@ test('Should clean the cache with external schemas', (t) => {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
t.assert.doesNotThrow(() => {
|
|
44
|
+
build(schema)
|
|
45
|
+
build(schema)
|
|
46
|
+
})
|
|
45
47
|
})
|
package/test/const.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const validator = require('is-my-json-valid')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
@@ -20,8 +20,8 @@ test('schema with const string', (t) => {
|
|
|
20
20
|
foo: 'bar'
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
t.equal(output, '{"foo":"bar"}')
|
|
24
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
23
|
+
t.assert.equal(output, '{"foo":"bar"}')
|
|
24
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
test('schema with const string and different input', (t) => {
|
|
@@ -40,8 +40,8 @@ test('schema with const string and different input', (t) => {
|
|
|
40
40
|
foo: 'baz'
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
t.equal(output, '{"foo":"bar"}')
|
|
44
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
43
|
+
t.assert.equal(output, '{"foo":"bar"}')
|
|
44
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
test('schema with const string and different type input', (t) => {
|
|
@@ -60,8 +60,8 @@ test('schema with const string and different type input', (t) => {
|
|
|
60
60
|
foo: 1
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
t.equal(output, '{"foo":"bar"}')
|
|
64
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
63
|
+
t.assert.equal(output, '{"foo":"bar"}')
|
|
64
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
test('schema with const string and no input', (t) => {
|
|
@@ -78,8 +78,8 @@ test('schema with const string and no input', (t) => {
|
|
|
78
78
|
const stringify = build(schema)
|
|
79
79
|
const output = stringify({})
|
|
80
80
|
|
|
81
|
-
t.equal(output, '{}')
|
|
82
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
81
|
+
t.assert.equal(output, '{}')
|
|
82
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
test('schema with const string that contains \'', (t) => {
|
|
@@ -98,8 +98,8 @@ test('schema with const string that contains \'', (t) => {
|
|
|
98
98
|
foo: "'bar'"
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
t.equal(output, '{"foo":"\'bar\'"}')
|
|
102
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
101
|
+
t.assert.equal(output, '{"foo":"\'bar\'"}')
|
|
102
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
103
103
|
})
|
|
104
104
|
|
|
105
105
|
test('schema with const number', (t) => {
|
|
@@ -118,8 +118,8 @@ test('schema with const number', (t) => {
|
|
|
118
118
|
foo: 1
|
|
119
119
|
})
|
|
120
120
|
|
|
121
|
-
t.equal(output, '{"foo":1}')
|
|
122
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
121
|
+
t.assert.equal(output, '{"foo":1}')
|
|
122
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
test('schema with const number and different input', (t) => {
|
|
@@ -138,8 +138,8 @@ test('schema with const number and different input', (t) => {
|
|
|
138
138
|
foo: 2
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
t.equal(output, '{"foo":1}')
|
|
142
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
141
|
+
t.assert.equal(output, '{"foo":1}')
|
|
142
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
143
143
|
})
|
|
144
144
|
|
|
145
145
|
test('schema with const bool', (t) => {
|
|
@@ -158,8 +158,8 @@ test('schema with const bool', (t) => {
|
|
|
158
158
|
foo: true
|
|
159
159
|
})
|
|
160
160
|
|
|
161
|
-
t.equal(output, '{"foo":true}')
|
|
162
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
161
|
+
t.assert.equal(output, '{"foo":true}')
|
|
162
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
163
163
|
})
|
|
164
164
|
|
|
165
165
|
test('schema with const number', (t) => {
|
|
@@ -178,8 +178,8 @@ test('schema with const number', (t) => {
|
|
|
178
178
|
foo: 1
|
|
179
179
|
})
|
|
180
180
|
|
|
181
|
-
t.equal(output, '{"foo":1}')
|
|
182
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
181
|
+
t.assert.equal(output, '{"foo":1}')
|
|
182
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
183
183
|
})
|
|
184
184
|
|
|
185
185
|
test('schema with const null', (t) => {
|
|
@@ -198,8 +198,8 @@ test('schema with const null', (t) => {
|
|
|
198
198
|
foo: null
|
|
199
199
|
})
|
|
200
200
|
|
|
201
|
-
t.equal(output, '{"foo":null}')
|
|
202
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
201
|
+
t.assert.equal(output, '{"foo":null}')
|
|
202
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
203
203
|
})
|
|
204
204
|
|
|
205
205
|
test('schema with const array', (t) => {
|
|
@@ -218,8 +218,8 @@ test('schema with const array', (t) => {
|
|
|
218
218
|
foo: [1, 2, 3]
|
|
219
219
|
})
|
|
220
220
|
|
|
221
|
-
t.equal(output, '{"foo":[1,2,3]}')
|
|
222
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
221
|
+
t.assert.equal(output, '{"foo":[1,2,3]}')
|
|
222
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
223
223
|
})
|
|
224
224
|
|
|
225
225
|
test('schema with const object', (t) => {
|
|
@@ -238,8 +238,8 @@ test('schema with const object', (t) => {
|
|
|
238
238
|
foo: { bar: 'baz' }
|
|
239
239
|
})
|
|
240
240
|
|
|
241
|
-
t.equal(output, '{"foo":{"bar":"baz"}}')
|
|
242
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
241
|
+
t.assert.equal(output, '{"foo":{"bar":"baz"}}')
|
|
242
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
243
243
|
})
|
|
244
244
|
|
|
245
245
|
test('schema with const and null as type', (t) => {
|
|
@@ -258,12 +258,12 @@ test('schema with const and null as type', (t) => {
|
|
|
258
258
|
foo: null
|
|
259
259
|
})
|
|
260
260
|
|
|
261
|
-
t.equal(output, '{"foo":null}')
|
|
262
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
261
|
+
t.assert.equal(output, '{"foo":null}')
|
|
262
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
263
263
|
|
|
264
264
|
const output2 = stringify({ foo: 'baz' })
|
|
265
|
-
t.equal(output2, '{"foo":"baz"}')
|
|
266
|
-
t.ok(validate(JSON.parse(output2)), 'valid schema')
|
|
265
|
+
t.assert.equal(output2, '{"foo":"baz"}')
|
|
266
|
+
t.assert.ok(validate(JSON.parse(output2)), 'valid schema')
|
|
267
267
|
})
|
|
268
268
|
|
|
269
269
|
test('schema with const as nullable', (t) => {
|
|
@@ -282,14 +282,14 @@ test('schema with const as nullable', (t) => {
|
|
|
282
282
|
foo: null
|
|
283
283
|
})
|
|
284
284
|
|
|
285
|
-
t.equal(output, '{"foo":null}')
|
|
286
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
285
|
+
t.assert.equal(output, '{"foo":null}')
|
|
286
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
287
287
|
|
|
288
288
|
const output2 = stringify({
|
|
289
289
|
foo: 'baz'
|
|
290
290
|
})
|
|
291
|
-
t.equal(output2, '{"foo":"baz"}')
|
|
292
|
-
t.ok(validate(JSON.parse(output2)), 'valid schema')
|
|
291
|
+
t.assert.equal(output2, '{"foo":"baz"}')
|
|
292
|
+
t.assert.ok(validate(JSON.parse(output2)), 'valid schema')
|
|
293
293
|
})
|
|
294
294
|
|
|
295
295
|
test('schema with const and invalid object', (t) => {
|
|
@@ -309,6 +309,6 @@ test('schema with const and invalid object', (t) => {
|
|
|
309
309
|
foo: { foo: 'baz' }
|
|
310
310
|
})
|
|
311
311
|
|
|
312
|
-
t.equal(result, '{"foo":{"foo":"bar"}}')
|
|
313
|
-
t.ok(validate(JSON.parse(result)), 'valid schema')
|
|
312
|
+
t.assert.equal(result, '{"foo":{"foo":"bar"}}')
|
|
313
|
+
t.assert.ok(validate(JSON.parse(result)), 'valid schema')
|
|
314
314
|
})
|