6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { JsonParseMode , parseJson , parseJsonAst } from './parser' ;
9
+ import { JsonParseMode , parseJsonAst } from './parser' ;
10
10
11
11
// Node 6 compatibility.
12
12
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
function entries ( x : { [ key : string ] : any } ) : any {
14
14
return Object . keys ( x ) . map ( ( k ) => [ k , x [ k ] ] ) ;
15
15
}
16
16
17
- describe ( 'parseJson and parseJsonAst' , ( ) => {
17
+ describe ( 'parseJsonAst' , ( ) => {
18
18
describe ( 'generic' , ( ) => {
19
19
const numbers = { } ;
20
20
const errors = [ '' , '-abcdefghijklmnopqrstuvwxyz' ] ;
@@ -25,15 +25,13 @@ describe('parseJson and parseJsonAst', () => {
25
25
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
26
26
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
27
27
expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
28
- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
29
28
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
30
29
} ) ;
31
30
}
32
31
33
32
for ( const n of errors ) {
34
33
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
35
34
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
36
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
37
35
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
38
36
} ) ;
39
37
}
@@ -98,15 +96,13 @@ describe('parseJson and parseJsonAst', () => {
98
96
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
99
97
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
100
98
expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
101
- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
102
99
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
103
100
} ) ;
104
101
}
105
102
106
103
for ( const n of errors ) {
107
104
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
108
105
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
109
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
110
106
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
111
107
} ) ;
112
108
}
@@ -144,15 +140,13 @@ describe('parseJson and parseJsonAst', () => {
144
140
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
145
141
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
146
142
expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
147
- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
148
143
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
149
144
} ) ;
150
145
}
151
146
152
147
for ( const n of errors ) {
153
148
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
154
149
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
155
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
156
150
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
157
151
} ) ;
158
152
}
@@ -180,7 +174,6 @@ describe('parseJson and parseJsonAst', () => {
180
174
for ( const n of errors ) {
181
175
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
182
176
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
183
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
184
177
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
185
178
} ) ;
186
179
}
@@ -223,15 +216,13 @@ describe('parseJson and parseJsonAst', () => {
223
216
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
224
217
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
225
218
expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
226
- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
227
219
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
228
220
} ) ;
229
221
}
230
222
231
223
for ( const n of errors ) {
232
224
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
233
225
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
234
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
235
226
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
236
227
} ) ;
237
228
}
@@ -269,15 +260,13 @@ describe('parseJson and parseJsonAst', () => {
269
260
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
270
261
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
271
262
expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
272
- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
273
263
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
274
264
} ) ;
275
265
}
276
266
277
267
for ( const n of errors ) {
278
268
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
279
269
expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
280
- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
281
270
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
282
271
} ) ;
283
272
}
@@ -322,76 +311,15 @@ describe('parseJson and parseJsonAst', () => {
322
311
expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
323
312
expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
324
313
expect ( ast . value ) . toEqual ( value ) ;
325
- expect ( parseJson ( n , JsonParseMode . Loose ) ) . toEqual ( value ) ;
326
314
expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
327
315
} ) ;
328
316
}
329
317
330
318
for ( const n of errors ) {
331
319
it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
332
320
expect ( ( ) => parseJsonAst ( n , JsonParseMode . Loose ) ) . toThrow ( ) ;
333
- expect ( ( ) => parseJson ( n , JsonParseMode . Loose ) ) . toThrow ( ) ;
334
321
expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
335
322
} ) ;
336
323
}
337
324
} ) ;
338
-
339
- describe ( 'complex' , ( ) => {
340
- it ( 'strips comments' , ( ) => {
341
- expect (
342
- parseJson (
343
- `
344
- // THIS IS A COMMENT
345
- {
346
- /* THIS IS ALSO A COMMENT */ // IGNORED BECAUSE COMMENT
347
- // AGAIN, COMMENT /* THIS SHOULD NOT BE WEIRD
348
- "a": "this // should not be a comment",
349
- "a2": "this /* should also not be a comment",
350
- /* MULTIPLE
351
- LINE
352
- COMMENT
353
- \\o/ */
354
- "b" /* COMMENT */: /* YOU GUESSED IT */ 1 // COMMENT
355
- , /* STILL VALID */
356
- "c": 2
357
- }
358
- ` ,
359
- JsonParseMode . Loose ,
360
- ) ,
361
- ) . toEqual ( {
362
- a : 'this // should not be a comment' ,
363
- a2 : 'this /* should also not be a comment' ,
364
- b : 1 ,
365
- c : 2 ,
366
- } ) ;
367
- } ) ;
368
-
369
- it ( 'works with json5.org example' , ( ) => {
370
- const input = `{
371
- // comments
372
- unquoted: 'and you can quote me on that',
373
- 'singleQuotes': 'I can use "double quotes" here',
374
- lineBreaks: "Look, Mom! \\
375
- No \\\\n's!",
376
- hexadecimal: 0xdecaf,
377
- leadingDecimalPoint: .8675309, andTrailing: 8675309.,
378
- positiveSign: +1,
379
- trailingComma: 'in objects', andIn: ['arrays',],
380
- "backwardsCompatible": "with JSON",
381
- }` ;
382
-
383
- expect ( parseJson ( input , JsonParseMode . Json5 ) ) . toEqual ( {
384
- unquoted : 'and you can quote me on that' ,
385
- singleQuotes : 'I can use "double quotes" here' ,
386
- lineBreaks : "Look, Mom! \nNo \\n's!" ,
387
- hexadecimal : 0xdecaf ,
388
- leadingDecimalPoint : 0.8675309 ,
389
- andTrailing : 8675309 ,
390
- positiveSign : + 1 ,
391
- trailingComma : 'in objects' ,
392
- andIn : [ 'arrays' ] ,
393
- backwardsCompatible : 'with JSON' ,
394
- } ) ;
395
- } ) ;
396
- } ) ;
397
325
} ) ;
0 commit comments