@@ -390,55 +390,63 @@ for (const [name, tests] of Object.entries(fixtures)) {
390
390
test . run ( ) ;
391
391
}
392
392
393
- const syntaxErrorFixtures = [
393
+ const invalid = [
394
394
{
395
395
name : 'empty string' ,
396
- json : ''
396
+ json : '' ,
397
+ message : 'Unexpected end of JSON input'
397
398
} ,
398
399
{
399
400
name : 'invalid JSON' ,
400
- json : ']['
401
+ json : '][' ,
402
+ message : 'Unexpected token ] in JSON at position 0'
401
403
} ,
402
404
{
403
405
name : 'hole' ,
404
- json : '-2'
406
+ json : '-2' ,
407
+ message : 'Unexpected number -2'
405
408
} ,
406
409
{
407
410
name : 'string' ,
408
411
json : '"hello"' ,
412
+ message : 'Expected array, got string'
409
413
} ,
410
414
{
411
415
name : 'number' ,
412
- json : '42'
416
+ json : '42' ,
417
+ message : 'Unexpected number 42'
413
418
} ,
414
419
{
415
420
name : 'boolean' ,
416
- json : 'true'
421
+ json : 'true' ,
422
+ message : 'Expected array, got boolean'
417
423
} ,
418
424
{
419
425
name : 'null' ,
420
- json : 'null'
426
+ json : 'null' ,
427
+ message : 'Expected array, got null'
421
428
} ,
422
429
{
423
430
name : 'object' ,
424
- json : '{}'
431
+ json : '{}' ,
432
+ message : 'Expected array, got object'
425
433
} ,
426
434
{
427
435
name : 'empty array' ,
428
- json : '[]'
436
+ json : '[]' ,
437
+ message : 'Unexpected empty array'
429
438
}
430
439
] ;
431
440
432
- const syntaxErrorTest = uvu . suite ( "parse: syntax errors" ) ;
433
-
434
- for ( const fixture of syntaxErrorFixtures ) {
435
- syntaxErrorTest ( fixture . name , ( ) => {
436
- assert . throws ( ( ) => parse ( fixture . json ) , ( error ) => error instanceof SyntaxError ) ;
441
+ for ( const { name, json, message } of invalid ) {
442
+ uvu . test ( `parse error: ${ name } ` , ( ) => {
443
+ assert . throws (
444
+ ( ) => parse ( json ) ,
445
+ ( error ) => error instanceof SyntaxError && error . message === message
446
+ ) ;
437
447
} ) ;
438
448
}
439
449
440
- syntaxErrorTest . run ( ) ;
441
-
442
450
for ( const fn of [ uneval , stringify ] ) {
443
451
uvu . test ( `${ fn . name } throws for non-POJOs` , ( ) => {
444
452
class Foo { }
0 commit comments