Skip to content

Commit 33f4c4d

Browse files
committed
chore: Add unit test for error location in the input with Window line breaks
1 parent fdf296e commit 33f4c4d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/parse1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ exports['test extra brace'] = function () {
259259
assert['throws'](function () { parse(json) }, 'should throw error')
260260
}
261261

262+
exports['test error location with Windows line breaks'] = function () {
263+
var json = '{\r\n"foo": {\r\n "bar":\r\n }\r\n \r\n }'
264+
try {
265+
parse(json)
266+
assert.fail('should throw error')
267+
} catch (error) {
268+
assert.equal(error.exzerpt, '... "bar": } }')
269+
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 }')
272+
assert.deepEqual(error.location, {
273+
start: { column: 5, line: 4, offset: 31 }
274+
})
275+
}
276+
}
277+
262278
exports['test pass-1'] = function () {
263279
var json = fs.readFileSync(path.join(__dirname, '/passes/1.json')).toString()
264280
assert.doesNotThrow(function () { parse(json) }, 'should pass')

0 commit comments

Comments
 (0)