Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/jju/test/test_errors.js')
-rw-r--r--node_modules/jju/test/test_errors.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/node_modules/jju/test/test_errors.js b/node_modules/jju/test/test_errors.js
new file mode 100644
index 000000000..8b2cdb7dc
--- /dev/null
+++ b/node_modules/jju/test/test_errors.js
@@ -0,0 +1,56 @@
+var assert = require('assert')
+var parse = require('../').parse
+
+function addTest(arg, row, col, errRegExp) {
+ var fn = function() {
+ try {
+ parse(arg)
+ } catch(err) {
+ if (row !== undefined) assert.equal(err.row, row, 'wrong row: ' + err.row)
+ if (col !== undefined) assert.equal(err.column, col, 'wrong column: ' + err.column)
+ if (errRegExp) assert(errRegExp.exec(err.message))
+ return
+ }
+ throw Error("no error")
+ }
+
+ if (typeof(describe) === 'function') {
+ it('test_errors: ' + JSON.stringify(arg), fn)
+ } else {
+ fn()
+ }
+}
+
+// semicolon will be unexpected, so it indicates an error position
+addTest(';', 1, 1)
+addTest('\n\n\n;', 4, 1)
+addTest('\r\n;', 2, 1)
+addTest('\n\r;', 3, 1)
+addTest('\n\u2028;', 3, 1)
+addTest('\n\u2029;', 3, 1)
+addTest('[\n1\n,\n;', 4, 1)
+addTest('{\n;', 2, 1)
+addTest('{\n1\n:\n;', 4, 1)
+addTest('.e3', 1, 3, /"\.e3"/)
+
+// line continuations
+addTest('["\\\n",\n;', 3, 1)
+addTest('["\\\r\n",\n;', 3, 1)
+addTest('["\\\u2028",\n;', 3, 1)
+addTest('["\\\u2029",\n;', 3, 1)
+
+// bareword rewind
+addTest('nulz', 1, 1)
+
+// no data
+addTest(' ', 1, 3, /No data.*whitespace/)
+addTest('blah', 1, 1, /Unexpected token 'b'/)
+addTest('', 1, 1, /No data.*empty input/)
+
+try {
+ parse('{{{{{{{{{')
+} catch(err) {
+ var x = err.stack.match(/parseObject/g)
+ assert(!x || x.length < 2, "shouldn't blow up the stack with internal calls")
+}
+