-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpartial-input.js
32 lines (31 loc) · 927 Bytes
/
partial-input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var test = require('tape')
var parse = require('../parser')
test('partial input', function (t) {
// These should all produce syntax errors at the end of the input
var inputs = [
"echo '",
'echo "',
'echo `start',
'echo $(',
'echo ${',
'if',
'while',
'until',
];
t.plan(inputs.length * 2)
inputs.forEach(function (input) {
try {
parse(input)
t.fail('parse(' + JSON.stringify(input) + ') parsed successfully when it should have thrown a SyntaxError')
} catch (errTop) {
t.equal(errTop.constructor, parse.SyntaxError, 'got a SyntaxError')
try {
var cont = input.slice(errTop.location.start.offset)
parse(cont, 'continuationStart')
t.pass(JSON.stringify(cont) + ' is a continuationStart')
} catch (errCont) {
t.fail(JSON.stringify(cont) + ' is not a continuationStart ' + errTop + ' ' + errCont)
}
}
})
})