@@ -27,15 +27,13 @@ function checkErrorInformation (error) {
27
27
}
28
28
}
29
29
30
- if ( ! nativeParser ) {
31
- exports [ 'test exported interface' ] = function ( ) {
32
- assert . equal ( typeof parse , 'function' )
33
- }
30
+ exports [ 'test exported interface' ] = function ( ) {
31
+ assert . equal ( typeof parse , 'function' )
32
+ }
34
33
35
- exports [ 'test function' ] = function ( ) {
36
- var json = '{"foo": "bar"}'
37
- assert . deepEqual ( parse ( json ) , { 'foo' : 'bar' } )
38
- }
34
+ exports [ 'test function' ] = function ( ) {
35
+ var json = '{"foo": "bar"}'
36
+ assert . deepEqual ( parse ( json ) , { 'foo' : 'bar' } )
39
37
}
40
38
41
39
exports [ 'test limited error information' ] = function ( ) {
@@ -259,19 +257,37 @@ exports['test extra brace'] = function () {
259
257
assert [ 'throws' ] ( function ( ) { parse ( json ) } , 'should throw error' )
260
258
}
261
259
262
- exports [ 'test error location with Windows line breaks' ] = function ( ) {
260
+ if ( ! oldNode ) {
261
+ exports [ 'test error location with Windows line breaks using the native parser' ] = function ( ) {
262
+ var json = '{\r\n"foo": {\r\n "bar":\r\n }\r\n \r\n }'
263
+ try {
264
+ exported . parseNative ( json )
265
+ assert . fail ( 'should throw error' )
266
+ } catch ( error ) {
267
+ assert . equal ( error . exzerpt , '... "bar": } }' )
268
+ assert . equal ( error . pointer , '-------------------^' )
269
+ assert . equal ( error . reason , 'Unexpected token }' )
270
+ assert . deepEqual ( error . location , {
271
+ start : { column : 5 , line : 4 , offset : 31 }
272
+ } )
273
+ assert . equal ( error . message , 'Parse error on line 4, column 5:\n... "bar": } }\n-------------------^\nUnexpected token }' )
274
+ }
275
+ }
276
+ }
277
+
278
+ exports [ 'test error location with Windows line breaks using the custom parser' ] = function ( ) {
263
279
var json = '{\r\n"foo": {\r\n "bar":\r\n }\r\n \r\n }'
264
280
try {
265
- parse ( json )
281
+ exported . parseCustom ( json )
266
282
assert . fail ( 'should throw error' )
267
283
} catch ( error ) {
268
284
assert . equal ( error . exzerpt , '... "bar": } }' )
269
285
assert . equal ( error . pointer , '-------------------^' )
270
- assert . equal ( error . reason , 'Unexpected token }' )
271
- assert . equal ( error . message , 'Parse error on line 4, column 5:\n... "bar": } }\n-------------------^\nUnexpected token }' )
286
+ assert . equal ( error . reason , 'No value found for key "bar"' )
272
287
assert . deepEqual ( error . location , {
273
288
start : { column : 5 , line : 4 , offset : 31 }
274
289
} )
290
+ assert . equal ( error . message , 'Parse error on line 4, column 5:\n... "bar": } }\n-------------------^\nNo value found for key "bar"' )
275
291
}
276
292
}
277
293
0 commit comments