From af9f1bda4d7d6e2e020457f6625b9c77dd1616fa Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Thu, 11 May 2017 19:38:40 +0300 Subject: [PATCH] test: add JSON5 specs test suite This commit adds and adapts the official JSON5 parser tests. `test/todo/json5.js` should be moved to `test/node` as soon as we fix all the failures. PR-URL: https://github.com/metarhia/JSTP/pull/158 Refs: https://github.com/metarhia/JSTP/issues/152 Reviewed-By: Dmytro Nechai Reviewed-By: Denys Otrishko Reviewed-By: Mykola Bilochub --- .bithoundrc | 3 +- .eslintignore | 1 + package.json | 1 + test/fixtures/json5/LICENSE.md | 21 ++++ test/fixtures/json5/README.md | 24 ++++ test/fixtures/json5/arrays/empty-array.json | 1 + .../json5/arrays/leading-comma-array.js | 3 + .../json5/arrays/lone-trailing-comma-array.js | 3 + .../json5/arrays/no-comma-array.errorSpec | 6 + test/fixtures/json5/arrays/no-comma-array.txt | 4 + test/fixtures/json5/arrays/regular-array.json | 5 + .../json5/arrays/trailing-comma-array.json5 | 3 + ...lock-comment-following-array-element.json5 | 6 + ...ck-comment-following-top-level-value.json5 | 5 + .../comments/block-comment-in-string.json | 1 + ...ck-comment-preceding-top-level-value.json5 | 5 + .../block-comment-with-asterisks.json5 | 7 ++ ...line-comment-following-array-element.json5 | 3 + ...ne-comment-following-top-level-value.json5 | 1 + .../comments/inline-comment-in-string.json | 1 + ...ne-comment-preceding-top-level-value.json5 | 2 + .../top-level-block-comment.errorSpec | 6 + .../comments/top-level-block-comment.txt | 4 + .../top-level-inline-comment.errorSpec | 6 + .../comments/top-level-inline-comment.txt | 1 + .../comments/unterminated-block-comment.txt | 5 + test/fixtures/json5/misc/empty.txt | 0 test/fixtures/json5/misc/npm-package.json | 106 ++++++++++++++++++ test/fixtures/json5/misc/npm-package.json5 | 106 ++++++++++++++++++ test/fixtures/json5/misc/readme-example.json5 | 25 +++++ .../json5/misc/valid-whitespace.json5 | 5 + test/fixtures/json5/new-lines/.editorconfig | 13 +++ test/fixtures/json5/new-lines/.gitattributes | 4 + .../fixtures/json5/new-lines/comment-cr.json5 | 1 + .../json5/new-lines/comment-crlf.json5 | 3 + .../fixtures/json5/new-lines/comment-lf.json5 | 3 + .../fixtures/json5/new-lines/escaped-cr.json5 | 1 + .../json5/new-lines/escaped-crlf.json5 | 5 + .../fixtures/json5/new-lines/escaped-lf.json5 | 5 + .../numbers/float-leading-decimal-point.json5 | 1 + .../json5/numbers/float-leading-zero.json | 1 + ...-decimal-point-with-integer-exponent.json5 | 1 + .../float-trailing-decimal-point.json5 | 1 + .../numbers/float-with-integer-exponent.json | 1 + test/fixtures/json5/numbers/float.json | 1 + .../json5/numbers/hexadecimal-empty.txt | 1 + .../hexadecimal-lowercase-letter.json5 | 1 + .../numbers/hexadecimal-uppercase-x.json5 | 1 + .../hexadecimal-with-integer-exponent.json5 | 1 + test/fixtures/json5/numbers/hexadecimal.json5 | 1 + test/fixtures/json5/numbers/infinity.json5 | 1 + .../numbers/integer-with-float-exponent.txt | 1 + .../integer-with-hexadecimal-exponent.txt | 1 + .../integer-with-integer-exponent.json | 1 + .../integer-with-negative-float-exponent.txt | 1 + ...ger-with-negative-hexadecimal-exponent.txt | 1 + ...nteger-with-negative-integer-exponent.json | 1 + ...r-with-negative-zero-integer-exponent.json | 1 + .../integer-with-positive-float-exponent.txt | 1 + ...ger-with-positive-hexadecimal-exponent.txt | 1 + ...nteger-with-positive-integer-exponent.json | 1 + ...r-with-positive-zero-integer-exponent.json | 1 + .../integer-with-zero-integer-exponent.json | 1 + test/fixtures/json5/numbers/integer.json | 1 + .../json5/numbers/lone-decimal-point.txt | 1 + test/fixtures/json5/numbers/nan.json5 | 1 + ...negative-float-leading-decimal-point.json5 | 1 + .../numbers/negative-float-leading-zero.json | 1 + ...egative-float-trailing-decimal-point.json5 | 1 + .../json5/numbers/negative-float.json | 1 + .../json5/numbers/negative-hexadecimal.json5 | 1 + .../json5/numbers/negative-infinity.json5 | 1 + .../json5/numbers/negative-integer.json | 1 + .../fixtures/json5/numbers/negative-noctal.js | 1 + .../fixtures/json5/numbers/negative-octal.txt | 1 + ...ive-zero-float-leading-decimal-point.json5 | 1 + ...ve-zero-float-trailing-decimal-point.json5 | 1 + .../json5/numbers/negative-zero-float.json | 1 + .../numbers/negative-zero-hexadecimal.json5 | 1 + .../json5/numbers/negative-zero-integer.json | 1 + .../json5/numbers/negative-zero-octal.txt | 1 + .../noctal-with-leading-octal-digit.js | 1 + test/fixtures/json5/numbers/noctal.js | 1 + test/fixtures/json5/numbers/octal.txt | 1 + ...positive-float-leading-decimal-point.json5 | 1 + .../numbers/positive-float-leading-zero.json5 | 1 + ...ositive-float-trailing-decimal-point.json5 | 1 + .../json5/numbers/positive-float.json5 | 1 + .../json5/numbers/positive-hexadecimal.json5 | 1 + .../json5/numbers/positive-infinity.json5 | 1 + .../json5/numbers/positive-integer.json5 | 1 + .../fixtures/json5/numbers/positive-noctal.js | 1 + .../fixtures/json5/numbers/positive-octal.txt | 1 + ...ive-zero-float-leading-decimal-point.json5 | 1 + ...ve-zero-float-trailing-decimal-point.json5 | 1 + .../json5/numbers/positive-zero-float.json5 | 1 + .../numbers/positive-zero-hexadecimal.json5 | 1 + .../json5/numbers/positive-zero-integer.json5 | 1 + .../json5/numbers/positive-zero-octal.txt | 1 + .../zero-float-leading-decimal-point.json5 | 1 + .../zero-float-trailing-decimal-point.json5 | 1 + test/fixtures/json5/numbers/zero-float.json | 1 + .../json5/numbers/zero-hexadecimal.json5 | 1 + .../zero-integer-with-integer-exponent.json | 1 + test/fixtures/json5/numbers/zero-integer.json | 1 + test/fixtures/json5/numbers/zero-octal.txt | 1 + .../json5/objects/duplicate-keys.json | 4 + test/fixtures/json5/objects/empty-object.json | 1 + .../illegal-unquoted-key-number.errorSpec | 6 + .../objects/illegal-unquoted-key-number.txt | 3 + .../illegal-unquoted-key-symbol.errorSpec | 6 + .../objects/illegal-unquoted-key-symbol.txt | 3 + .../objects/leading-comma-object.errorSpec | 6 + .../json5/objects/leading-comma-object.txt | 3 + .../objects/lone-trailing-comma-object.txt | 3 + .../json5/objects/no-comma-object.txt | 4 + .../json5/objects/reserved-unquoted-key.json5 | 3 + .../json5/objects/single-quoted-key.json5 | 3 + .../json5/objects/trailing-comma-object.json5 | 3 + .../json5/objects/unquoted-keys.json5 | 8 ++ .../escaped-single-quoted-string.json5 | 1 + .../json5/strings/multi-line-string.json5 | 2 + .../json5/strings/no-comma-array.errorSpec | 6 + .../json5/strings/single-quoted-string.json5 | 1 + .../unescaped-multi-line-string.errorSpec | 6 + .../strings/unescaped-multi-line-string.txt | 2 + .../todo/unicode-escaped-unquoted-key.json5 | 3 + .../json5/todo/unicode-unquoted-key.json5 | 3 + test/todo/json5.js | 81 +++++++++++++ 129 files changed, 632 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/json5/LICENSE.md create mode 100644 test/fixtures/json5/README.md create mode 100644 test/fixtures/json5/arrays/empty-array.json create mode 100644 test/fixtures/json5/arrays/leading-comma-array.js create mode 100644 test/fixtures/json5/arrays/lone-trailing-comma-array.js create mode 100644 test/fixtures/json5/arrays/no-comma-array.errorSpec create mode 100644 test/fixtures/json5/arrays/no-comma-array.txt create mode 100644 test/fixtures/json5/arrays/regular-array.json create mode 100644 test/fixtures/json5/arrays/trailing-comma-array.json5 create mode 100644 test/fixtures/json5/comments/block-comment-following-array-element.json5 create mode 100644 test/fixtures/json5/comments/block-comment-following-top-level-value.json5 create mode 100644 test/fixtures/json5/comments/block-comment-in-string.json create mode 100644 test/fixtures/json5/comments/block-comment-preceding-top-level-value.json5 create mode 100644 test/fixtures/json5/comments/block-comment-with-asterisks.json5 create mode 100644 test/fixtures/json5/comments/inline-comment-following-array-element.json5 create mode 100644 test/fixtures/json5/comments/inline-comment-following-top-level-value.json5 create mode 100644 test/fixtures/json5/comments/inline-comment-in-string.json create mode 100644 test/fixtures/json5/comments/inline-comment-preceding-top-level-value.json5 create mode 100644 test/fixtures/json5/comments/top-level-block-comment.errorSpec create mode 100644 test/fixtures/json5/comments/top-level-block-comment.txt create mode 100644 test/fixtures/json5/comments/top-level-inline-comment.errorSpec create mode 100644 test/fixtures/json5/comments/top-level-inline-comment.txt create mode 100644 test/fixtures/json5/comments/unterminated-block-comment.txt create mode 100644 test/fixtures/json5/misc/empty.txt create mode 100644 test/fixtures/json5/misc/npm-package.json create mode 100644 test/fixtures/json5/misc/npm-package.json5 create mode 100644 test/fixtures/json5/misc/readme-example.json5 create mode 100644 test/fixtures/json5/misc/valid-whitespace.json5 create mode 100644 test/fixtures/json5/new-lines/.editorconfig create mode 100644 test/fixtures/json5/new-lines/.gitattributes create mode 100644 test/fixtures/json5/new-lines/comment-cr.json5 create mode 100644 test/fixtures/json5/new-lines/comment-crlf.json5 create mode 100644 test/fixtures/json5/new-lines/comment-lf.json5 create mode 100644 test/fixtures/json5/new-lines/escaped-cr.json5 create mode 100644 test/fixtures/json5/new-lines/escaped-crlf.json5 create mode 100644 test/fixtures/json5/new-lines/escaped-lf.json5 create mode 100644 test/fixtures/json5/numbers/float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/float-leading-zero.json create mode 100644 test/fixtures/json5/numbers/float-trailing-decimal-point-with-integer-exponent.json5 create mode 100644 test/fixtures/json5/numbers/float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/float-with-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/float.json create mode 100644 test/fixtures/json5/numbers/hexadecimal-empty.txt create mode 100644 test/fixtures/json5/numbers/hexadecimal-lowercase-letter.json5 create mode 100644 test/fixtures/json5/numbers/hexadecimal-uppercase-x.json5 create mode 100644 test/fixtures/json5/numbers/hexadecimal-with-integer-exponent.json5 create mode 100644 test/fixtures/json5/numbers/hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/infinity.json5 create mode 100644 test/fixtures/json5/numbers/integer-with-float-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-hexadecimal-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer-with-negative-float-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-negative-hexadecimal-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-negative-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer-with-negative-zero-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer-with-positive-float-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-positive-hexadecimal-exponent.txt create mode 100644 test/fixtures/json5/numbers/integer-with-positive-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer-with-positive-zero-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer-with-zero-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/integer.json create mode 100644 test/fixtures/json5/numbers/lone-decimal-point.txt create mode 100644 test/fixtures/json5/numbers/nan.json5 create mode 100644 test/fixtures/json5/numbers/negative-float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/negative-float-leading-zero.json create mode 100644 test/fixtures/json5/numbers/negative-float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/negative-float.json create mode 100644 test/fixtures/json5/numbers/negative-hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/negative-infinity.json5 create mode 100644 test/fixtures/json5/numbers/negative-integer.json create mode 100644 test/fixtures/json5/numbers/negative-noctal.js create mode 100644 test/fixtures/json5/numbers/negative-octal.txt create mode 100644 test/fixtures/json5/numbers/negative-zero-float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/negative-zero-float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/negative-zero-float.json create mode 100644 test/fixtures/json5/numbers/negative-zero-hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/negative-zero-integer.json create mode 100644 test/fixtures/json5/numbers/negative-zero-octal.txt create mode 100644 test/fixtures/json5/numbers/noctal-with-leading-octal-digit.js create mode 100644 test/fixtures/json5/numbers/noctal.js create mode 100644 test/fixtures/json5/numbers/octal.txt create mode 100644 test/fixtures/json5/numbers/positive-float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/positive-float-leading-zero.json5 create mode 100644 test/fixtures/json5/numbers/positive-float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/positive-float.json5 create mode 100644 test/fixtures/json5/numbers/positive-hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/positive-infinity.json5 create mode 100644 test/fixtures/json5/numbers/positive-integer.json5 create mode 100644 test/fixtures/json5/numbers/positive-noctal.js create mode 100644 test/fixtures/json5/numbers/positive-octal.txt create mode 100644 test/fixtures/json5/numbers/positive-zero-float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/positive-zero-float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/positive-zero-float.json5 create mode 100644 test/fixtures/json5/numbers/positive-zero-hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/positive-zero-integer.json5 create mode 100644 test/fixtures/json5/numbers/positive-zero-octal.txt create mode 100644 test/fixtures/json5/numbers/zero-float-leading-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/zero-float-trailing-decimal-point.json5 create mode 100644 test/fixtures/json5/numbers/zero-float.json create mode 100644 test/fixtures/json5/numbers/zero-hexadecimal.json5 create mode 100644 test/fixtures/json5/numbers/zero-integer-with-integer-exponent.json create mode 100644 test/fixtures/json5/numbers/zero-integer.json create mode 100644 test/fixtures/json5/numbers/zero-octal.txt create mode 100644 test/fixtures/json5/objects/duplicate-keys.json create mode 100644 test/fixtures/json5/objects/empty-object.json create mode 100644 test/fixtures/json5/objects/illegal-unquoted-key-number.errorSpec create mode 100644 test/fixtures/json5/objects/illegal-unquoted-key-number.txt create mode 100644 test/fixtures/json5/objects/illegal-unquoted-key-symbol.errorSpec create mode 100644 test/fixtures/json5/objects/illegal-unquoted-key-symbol.txt create mode 100644 test/fixtures/json5/objects/leading-comma-object.errorSpec create mode 100644 test/fixtures/json5/objects/leading-comma-object.txt create mode 100644 test/fixtures/json5/objects/lone-trailing-comma-object.txt create mode 100644 test/fixtures/json5/objects/no-comma-object.txt create mode 100644 test/fixtures/json5/objects/reserved-unquoted-key.json5 create mode 100644 test/fixtures/json5/objects/single-quoted-key.json5 create mode 100644 test/fixtures/json5/objects/trailing-comma-object.json5 create mode 100644 test/fixtures/json5/objects/unquoted-keys.json5 create mode 100644 test/fixtures/json5/strings/escaped-single-quoted-string.json5 create mode 100644 test/fixtures/json5/strings/multi-line-string.json5 create mode 100644 test/fixtures/json5/strings/no-comma-array.errorSpec create mode 100644 test/fixtures/json5/strings/single-quoted-string.json5 create mode 100644 test/fixtures/json5/strings/unescaped-multi-line-string.errorSpec create mode 100644 test/fixtures/json5/strings/unescaped-multi-line-string.txt create mode 100644 test/fixtures/json5/todo/unicode-escaped-unquoted-key.json5 create mode 100644 test/fixtures/json5/todo/unicode-unquoted-key.json5 create mode 100644 test/todo/json5.js diff --git a/.bithoundrc b/.bithoundrc index 8724b331..0f091f15 100644 --- a/.bithoundrc +++ b/.bithoundrc @@ -8,7 +8,8 @@ } }, "ignore": [ - "**/node_modules/**" + "**/node_modules/**", + "test/fixtures/json5/**" ], "test": [ "test/**" diff --git a/.eslintignore b/.eslintignore index b3297c55..bb1c6e3b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ node_modules/ dist/ site/ examples/data-formats/*.js +test/fixtures/json5/**/*.js diff --git a/package.json b/package.json index e3045c89..ca659306 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "test-unit-browser": "karma start", "test-integration": "node test/integration/run-tests", "test-browser-unit": "karma start", + "test-todo": "tap test/todo", "lint": "eslint . && remark .", "install": "npm run rebuild-node", "build": "npm run build-node && npm run build-browser", diff --git a/test/fixtures/json5/LICENSE.md b/test/fixtures/json5/LICENSE.md new file mode 100644 index 00000000..ae4049bb --- /dev/null +++ b/test/fixtures/json5/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-2016 Aseem Kishore, and [others](https://github.com/json5/json5/contributors). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/json5/README.md b/test/fixtures/json5/README.md new file mode 100644 index 00000000..eabd3f33 --- /dev/null +++ b/test/fixtures/json5/README.md @@ -0,0 +1,24 @@ +*Note*: this is forked from https://github.com/json5/json5-tests + +# Parse Test Cases for JSON5 + +The test cases' file extension signals the expected behavior: + +- Valid JSON should remain valid JSON5. These cases have a `.json` extension + and are tested via `JSON.parse()`. + +- JSON5's new features should remain valid ES5. These cases have a `.json5` + extension are tested via `eval()`. + +- Valid ES5 that's explicitly disallowed by JSON5 is also invalid JSON. These + cases have a `.js` extension and are expected to fail. + +- Invalid ES5 should remain invalid JSON5. These cases have a `.txt` extension + and are expected to fail. + +This should cover all our bases. Most of the cases are unit tests for each +supported data type, but aggregate test cases are welcome, too. + +## License + +MIT. See [LICENSE.md](./LICENSE.md) for details. diff --git a/test/fixtures/json5/arrays/empty-array.json b/test/fixtures/json5/arrays/empty-array.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/fixtures/json5/arrays/empty-array.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixtures/json5/arrays/leading-comma-array.js b/test/fixtures/json5/arrays/leading-comma-array.js new file mode 100644 index 00000000..23c097c0 --- /dev/null +++ b/test/fixtures/json5/arrays/leading-comma-array.js @@ -0,0 +1,3 @@ +[ + ,null +] \ No newline at end of file diff --git a/test/fixtures/json5/arrays/lone-trailing-comma-array.js b/test/fixtures/json5/arrays/lone-trailing-comma-array.js new file mode 100644 index 00000000..013b45c5 --- /dev/null +++ b/test/fixtures/json5/arrays/lone-trailing-comma-array.js @@ -0,0 +1,3 @@ +[ + , +] \ No newline at end of file diff --git a/test/fixtures/json5/arrays/no-comma-array.errorSpec b/test/fixtures/json5/arrays/no-comma-array.errorSpec new file mode 100644 index 00000000..b476eca8 --- /dev/null +++ b/test/fixtures/json5/arrays/no-comma-array.errorSpec @@ -0,0 +1,6 @@ +{ + at: 16, + lineNumber: 3, + columnNumber: 5, + message: "Expected ']' instead of 'f'" +} \ No newline at end of file diff --git a/test/fixtures/json5/arrays/no-comma-array.txt b/test/fixtures/json5/arrays/no-comma-array.txt new file mode 100644 index 00000000..22b41c10 --- /dev/null +++ b/test/fixtures/json5/arrays/no-comma-array.txt @@ -0,0 +1,4 @@ +[ + true + false +] \ No newline at end of file diff --git a/test/fixtures/json5/arrays/regular-array.json b/test/fixtures/json5/arrays/regular-array.json new file mode 100644 index 00000000..90727802 --- /dev/null +++ b/test/fixtures/json5/arrays/regular-array.json @@ -0,0 +1,5 @@ +[ + true, + false, + null +] \ No newline at end of file diff --git a/test/fixtures/json5/arrays/trailing-comma-array.json5 b/test/fixtures/json5/arrays/trailing-comma-array.json5 new file mode 100644 index 00000000..6e6b6ede --- /dev/null +++ b/test/fixtures/json5/arrays/trailing-comma-array.json5 @@ -0,0 +1,3 @@ +[ + null, +] \ No newline at end of file diff --git a/test/fixtures/json5/comments/block-comment-following-array-element.json5 b/test/fixtures/json5/comments/block-comment-following-array-element.json5 new file mode 100644 index 00000000..8677f63d --- /dev/null +++ b/test/fixtures/json5/comments/block-comment-following-array-element.json5 @@ -0,0 +1,6 @@ +[ + false + /* + true + */ +] \ No newline at end of file diff --git a/test/fixtures/json5/comments/block-comment-following-top-level-value.json5 b/test/fixtures/json5/comments/block-comment-following-top-level-value.json5 new file mode 100644 index 00000000..1e6ccfd2 --- /dev/null +++ b/test/fixtures/json5/comments/block-comment-following-top-level-value.json5 @@ -0,0 +1,5 @@ +null +/* + Some non-comment top-level value is needed; + we use null above. +*/ \ No newline at end of file diff --git a/test/fixtures/json5/comments/block-comment-in-string.json b/test/fixtures/json5/comments/block-comment-in-string.json new file mode 100644 index 00000000..7d2916c5 --- /dev/null +++ b/test/fixtures/json5/comments/block-comment-in-string.json @@ -0,0 +1 @@ +"This /* block comment */ isn't really a block comment." \ No newline at end of file diff --git a/test/fixtures/json5/comments/block-comment-preceding-top-level-value.json5 b/test/fixtures/json5/comments/block-comment-preceding-top-level-value.json5 new file mode 100644 index 00000000..df1e5204 --- /dev/null +++ b/test/fixtures/json5/comments/block-comment-preceding-top-level-value.json5 @@ -0,0 +1,5 @@ +/* + Some non-comment top-level value is needed; + we use null below. +*/ +null \ No newline at end of file diff --git a/test/fixtures/json5/comments/block-comment-with-asterisks.json5 b/test/fixtures/json5/comments/block-comment-with-asterisks.json5 new file mode 100644 index 00000000..94c44e79 --- /dev/null +++ b/test/fixtures/json5/comments/block-comment-with-asterisks.json5 @@ -0,0 +1,7 @@ +/** + * This is a JavaDoc-like block comment. + * It contains asterisks inside of it. + * It might also be closed with multiple asterisks. + * Like this: + **/ +true \ No newline at end of file diff --git a/test/fixtures/json5/comments/inline-comment-following-array-element.json5 b/test/fixtures/json5/comments/inline-comment-following-array-element.json5 new file mode 100644 index 00000000..d6a3f8c6 --- /dev/null +++ b/test/fixtures/json5/comments/inline-comment-following-array-element.json5 @@ -0,0 +1,3 @@ +[ + false // true +] \ No newline at end of file diff --git a/test/fixtures/json5/comments/inline-comment-following-top-level-value.json5 b/test/fixtures/json5/comments/inline-comment-following-top-level-value.json5 new file mode 100644 index 00000000..cf9ed019 --- /dev/null +++ b/test/fixtures/json5/comments/inline-comment-following-top-level-value.json5 @@ -0,0 +1 @@ +null // Some non-comment top-level value is needed; we use null here. \ No newline at end of file diff --git a/test/fixtures/json5/comments/inline-comment-in-string.json b/test/fixtures/json5/comments/inline-comment-in-string.json new file mode 100644 index 00000000..f0fb14f6 --- /dev/null +++ b/test/fixtures/json5/comments/inline-comment-in-string.json @@ -0,0 +1 @@ +"This inline comment // isn't really an inline comment." \ No newline at end of file diff --git a/test/fixtures/json5/comments/inline-comment-preceding-top-level-value.json5 b/test/fixtures/json5/comments/inline-comment-preceding-top-level-value.json5 new file mode 100644 index 00000000..d4b9b4d1 --- /dev/null +++ b/test/fixtures/json5/comments/inline-comment-preceding-top-level-value.json5 @@ -0,0 +1,2 @@ +// Some non-comment top-level value is needed; we use null below. +null \ No newline at end of file diff --git a/test/fixtures/json5/comments/top-level-block-comment.errorSpec b/test/fixtures/json5/comments/top-level-block-comment.errorSpec new file mode 100644 index 00000000..9bf5cf51 --- /dev/null +++ b/test/fixtures/json5/comments/top-level-block-comment.errorSpec @@ -0,0 +1,6 @@ +{ + at: 77, + lineNumber: 4, + columnNumber: 3, + message: "Unexpected EOF" +} \ No newline at end of file diff --git a/test/fixtures/json5/comments/top-level-block-comment.txt b/test/fixtures/json5/comments/top-level-block-comment.txt new file mode 100644 index 00000000..7466bd2c --- /dev/null +++ b/test/fixtures/json5/comments/top-level-block-comment.txt @@ -0,0 +1,4 @@ +/* + This should fail; + comments cannot be the only top-level value. +*/ \ No newline at end of file diff --git a/test/fixtures/json5/comments/top-level-inline-comment.errorSpec b/test/fixtures/json5/comments/top-level-inline-comment.errorSpec new file mode 100644 index 00000000..3d915cd4 --- /dev/null +++ b/test/fixtures/json5/comments/top-level-inline-comment.errorSpec @@ -0,0 +1,6 @@ +{ + at: 66, + lineNumber: 1, + columnNumber: 67, + message: "Unexpected EOF" +} \ No newline at end of file diff --git a/test/fixtures/json5/comments/top-level-inline-comment.txt b/test/fixtures/json5/comments/top-level-inline-comment.txt new file mode 100644 index 00000000..c5577f19 --- /dev/null +++ b/test/fixtures/json5/comments/top-level-inline-comment.txt @@ -0,0 +1 @@ +// This should fail; comments cannot be the only top-level value. \ No newline at end of file diff --git a/test/fixtures/json5/comments/unterminated-block-comment.txt b/test/fixtures/json5/comments/unterminated-block-comment.txt new file mode 100644 index 00000000..627b7bd1 --- /dev/null +++ b/test/fixtures/json5/comments/unterminated-block-comment.txt @@ -0,0 +1,5 @@ +true +/* + This block comment doesn't terminate. + There was a legitimate value before this, + but this is still invalid JS/JSON5. diff --git a/test/fixtures/json5/misc/empty.txt b/test/fixtures/json5/misc/empty.txt new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/json5/misc/npm-package.json b/test/fixtures/json5/misc/npm-package.json new file mode 100644 index 00000000..85568da1 --- /dev/null +++ b/test/fixtures/json5/misc/npm-package.json @@ -0,0 +1,106 @@ +{ + "name": "npm", + "publishConfig": { + "proprietary-attribs": false + }, + "description": "A package manager for node", + "keywords": [ + "package manager", + "modules", + "install", + "package.json" + ], + "version": "1.1.22", + "preferGlobal": true, + "config": { + "publishtest": false + }, + "homepage": "http://npmjs.org/", + "author": "Isaac Z. Schlueter (http://blog.izs.me)", + "repository": { + "type": "git", + "url": "https://github.com/isaacs/npm" + }, + "bugs": { + "email": "npm-@googlegroups.com", + "url": "http://github.com/isaacs/npm/issues" + }, + "directories": { + "doc": "./doc", + "man": "./man", + "lib": "./lib", + "bin": "./bin" + }, + "main": "./lib/npm.js", + "bin": "./bin/npm-cli.js", + "dependencies": { + "semver": "~1.0.14", + "ini": "1", + "slide": "1", + "abbrev": "1", + "graceful-fs": "~1.1.1", + "minimatch": "~0.2", + "nopt": "1", + "node-uuid": "~1.3", + "proto-list": "1", + "rimraf": "2", + "request": "~2.9", + "which": "1", + "tar": "~0.1.12", + "fstream": "~0.1.17", + "block-stream": "*", + "inherits": "1", + "mkdirp": "0.3", + "read": "0", + "lru-cache": "1", + "node-gyp": "~0.4.1", + "fstream-npm": "0 >=0.0.5", + "uid-number": "0", + "archy": "0", + "chownr": "0" + }, + "bundleDependencies": [ + "slide", + "ini", + "semver", + "abbrev", + "graceful-fs", + "minimatch", + "nopt", + "node-uuid", + "rimraf", + "request", + "proto-list", + "which", + "tar", + "fstream", + "block-stream", + "inherits", + "mkdirp", + "read", + "lru-cache", + "node-gyp", + "fstream-npm", + "uid-number", + "archy", + "chownr" + ], + "devDependencies": { + "ronn": "https://github.com/isaacs/ronnjs/tarball/master" + }, + "engines": { + "node": "0.6 || 0.7 || 0.8", + "npm": "1" + }, + "scripts": { + "test": "node ./test/run.js", + "prepublish": "npm prune; rm -rf node_modules/*/{test,example,bench}*; make -j4 doc", + "dumpconf": "env | grep npm | sort | uniq" + }, + "licenses": [ + { + "type": "MIT +no-false-attribs", + "url": "http://github.com/isaacs/npm/raw/master/LICENSE" + } + ] +} diff --git a/test/fixtures/json5/misc/npm-package.json5 b/test/fixtures/json5/misc/npm-package.json5 new file mode 100644 index 00000000..69944065 --- /dev/null +++ b/test/fixtures/json5/misc/npm-package.json5 @@ -0,0 +1,106 @@ +{ + name: 'npm', + publishConfig: { + 'proprietary-attribs': false, + }, + description: 'A package manager for node', + keywords: [ + 'package manager', + 'modules', + 'install', + 'package.json', + ], + version: '1.1.22', + preferGlobal: true, + config: { + publishtest: false, + }, + homepage: 'http://npmjs.org/', + author: 'Isaac Z. Schlueter (http://blog.izs.me)', + repository: { + type: 'git', + url: 'https://github.com/isaacs/npm', + }, + bugs: { + email: 'npm-@googlegroups.com', + url: 'http://github.com/isaacs/npm/issues', + }, + directories: { + doc: './doc', + man: './man', + lib: './lib', + bin: './bin', + }, + main: './lib/npm.js', + bin: './bin/npm-cli.js', + dependencies: { + semver: '~1.0.14', + ini: '1', + slide: '1', + abbrev: '1', + 'graceful-fs': '~1.1.1', + minimatch: '~0.2', + nopt: '1', + 'node-uuid': '~1.3', + 'proto-list': '1', + rimraf: '2', + request: '~2.9', + which: '1', + tar: '~0.1.12', + fstream: '~0.1.17', + 'block-stream': '*', + inherits: '1', + mkdirp: '0.3', + read: '0', + 'lru-cache': '1', + 'node-gyp': '~0.4.1', + 'fstream-npm': '0 >=0.0.5', + 'uid-number': '0', + archy: '0', + chownr: '0', + }, + bundleDependencies: [ + 'slide', + 'ini', + 'semver', + 'abbrev', + 'graceful-fs', + 'minimatch', + 'nopt', + 'node-uuid', + 'rimraf', + 'request', + 'proto-list', + 'which', + 'tar', + 'fstream', + 'block-stream', + 'inherits', + 'mkdirp', + 'read', + 'lru-cache', + 'node-gyp', + 'fstream-npm', + 'uid-number', + 'archy', + 'chownr', + ], + devDependencies: { + ronn: 'https://github.com/isaacs/ronnjs/tarball/master', + }, + engines: { + node: '0.6 || 0.7 || 0.8', + npm: '1', + }, + scripts: { + test: 'node ./test/run.js', + prepublish: 'npm prune; rm -rf node_modules/*/{test,example,bench}*; make -j4 doc', + dumpconf: 'env | grep npm | sort | uniq', + }, + licenses: [ + { + type: 'MIT +no-false-attribs', + url: 'http://github.com/isaacs/npm/raw/master/LICENSE', + }, + ], +} diff --git a/test/fixtures/json5/misc/readme-example.json5 b/test/fixtures/json5/misc/readme-example.json5 new file mode 100644 index 00000000..25c920a3 --- /dev/null +++ b/test/fixtures/json5/misc/readme-example.json5 @@ -0,0 +1,25 @@ +{ + foo: 'bar', + while: true, + + this: 'is a \ +multi-line string', + + // this is an inline comment + here: 'is another', // inline comment + + /* this is a block comment + that continues on another line */ + + hex: 0xDEADbeef, + half: .5, + delta: +10, + to: Infinity, // and beyond! + + finally: 'a trailing comma', + oh: [ + "we shouldn't forget", + 'arrays can have', + 'trailing commas too', + ], +} diff --git a/test/fixtures/json5/misc/valid-whitespace.json5 b/test/fixtures/json5/misc/valid-whitespace.json5 new file mode 100644 index 00000000..5cb57d36 --- /dev/null +++ b/test/fixtures/json5/misc/valid-whitespace.json5 @@ -0,0 +1,5 @@ +{ + // An invalid form feed character (\x0c) has been entered before this comment. + // Be careful not to delete it. + "a": true +} diff --git a/test/fixtures/json5/new-lines/.editorconfig b/test/fixtures/json5/new-lines/.editorconfig new file mode 100644 index 00000000..1784f9e3 --- /dev/null +++ b/test/fixtures/json5/new-lines/.editorconfig @@ -0,0 +1,13 @@ +# Since we're testing different representations of new lines, +# make sure the editor doesn't mangle line endings. +# Don't commit files in this directory unless you've checked +# their escaped new lines. + +[*-lf.*] +end_of_line = lf + +[*-cr.*] +end_of_line = cr + +[*-crlf.*] +end_of_line = crlf diff --git a/test/fixtures/json5/new-lines/.gitattributes b/test/fixtures/json5/new-lines/.gitattributes new file mode 100644 index 00000000..2b3eea69 --- /dev/null +++ b/test/fixtures/json5/new-lines/.gitattributes @@ -0,0 +1,4 @@ +# Since we're testing different representations of new lines, +# treat all tests in this folder as binary files. + +* binary diff --git a/test/fixtures/json5/new-lines/comment-cr.json5 b/test/fixtures/json5/new-lines/comment-cr.json5 new file mode 100644 index 00000000..91eb95bd --- /dev/null +++ b/test/fixtures/json5/new-lines/comment-cr.json5 @@ -0,0 +1 @@ +{ // This comment is terminated with `\r`. } \ No newline at end of file diff --git a/test/fixtures/json5/new-lines/comment-crlf.json5 b/test/fixtures/json5/new-lines/comment-crlf.json5 new file mode 100644 index 00000000..21ba2134 --- /dev/null +++ b/test/fixtures/json5/new-lines/comment-crlf.json5 @@ -0,0 +1,3 @@ +{ + // This comment is terminated with `\r\n`. +} diff --git a/test/fixtures/json5/new-lines/comment-lf.json5 b/test/fixtures/json5/new-lines/comment-lf.json5 new file mode 100644 index 00000000..e17dd72c --- /dev/null +++ b/test/fixtures/json5/new-lines/comment-lf.json5 @@ -0,0 +1,3 @@ +{ + // This comment is terminated with `\n`. +} diff --git a/test/fixtures/json5/new-lines/escaped-cr.json5 b/test/fixtures/json5/new-lines/escaped-cr.json5 new file mode 100644 index 00000000..5969903d --- /dev/null +++ b/test/fixtures/json5/new-lines/escaped-cr.json5 @@ -0,0 +1 @@ +{ // the following string contains an escaped `\r` a: 'line 1 \ line 2' } \ No newline at end of file diff --git a/test/fixtures/json5/new-lines/escaped-crlf.json5 b/test/fixtures/json5/new-lines/escaped-crlf.json5 new file mode 100644 index 00000000..7be9435e --- /dev/null +++ b/test/fixtures/json5/new-lines/escaped-crlf.json5 @@ -0,0 +1,5 @@ +{ + // the following string contains an escaped `\r\n` + a: 'line 1 \ +line 2' +} diff --git a/test/fixtures/json5/new-lines/escaped-lf.json5 b/test/fixtures/json5/new-lines/escaped-lf.json5 new file mode 100644 index 00000000..2235e8c7 --- /dev/null +++ b/test/fixtures/json5/new-lines/escaped-lf.json5 @@ -0,0 +1,5 @@ +{ + // the following string contains an escaped `\n` + a: 'line 1 \ +line 2' +} diff --git a/test/fixtures/json5/numbers/float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/float-leading-decimal-point.json5 new file mode 100644 index 00000000..d6c9fff3 --- /dev/null +++ b/test/fixtures/json5/numbers/float-leading-decimal-point.json5 @@ -0,0 +1 @@ +.5 diff --git a/test/fixtures/json5/numbers/float-leading-zero.json b/test/fixtures/json5/numbers/float-leading-zero.json new file mode 100644 index 00000000..2eb3c4fe --- /dev/null +++ b/test/fixtures/json5/numbers/float-leading-zero.json @@ -0,0 +1 @@ +0.5 diff --git a/test/fixtures/json5/numbers/float-trailing-decimal-point-with-integer-exponent.json5 b/test/fixtures/json5/numbers/float-trailing-decimal-point-with-integer-exponent.json5 new file mode 100644 index 00000000..70b87207 --- /dev/null +++ b/test/fixtures/json5/numbers/float-trailing-decimal-point-with-integer-exponent.json5 @@ -0,0 +1 @@ +5.e4 diff --git a/test/fixtures/json5/numbers/float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/float-trailing-decimal-point.json5 new file mode 100644 index 00000000..e4c8c313 --- /dev/null +++ b/test/fixtures/json5/numbers/float-trailing-decimal-point.json5 @@ -0,0 +1 @@ +5. diff --git a/test/fixtures/json5/numbers/float-with-integer-exponent.json b/test/fixtures/json5/numbers/float-with-integer-exponent.json new file mode 100644 index 00000000..0e957c63 --- /dev/null +++ b/test/fixtures/json5/numbers/float-with-integer-exponent.json @@ -0,0 +1 @@ +1.2e3 diff --git a/test/fixtures/json5/numbers/float.json b/test/fixtures/json5/numbers/float.json new file mode 100644 index 00000000..5625e59d --- /dev/null +++ b/test/fixtures/json5/numbers/float.json @@ -0,0 +1 @@ +1.2 diff --git a/test/fixtures/json5/numbers/hexadecimal-empty.txt b/test/fixtures/json5/numbers/hexadecimal-empty.txt new file mode 100644 index 00000000..ec687260 --- /dev/null +++ b/test/fixtures/json5/numbers/hexadecimal-empty.txt @@ -0,0 +1 @@ +0x diff --git a/test/fixtures/json5/numbers/hexadecimal-lowercase-letter.json5 b/test/fixtures/json5/numbers/hexadecimal-lowercase-letter.json5 new file mode 100644 index 00000000..57e27eed --- /dev/null +++ b/test/fixtures/json5/numbers/hexadecimal-lowercase-letter.json5 @@ -0,0 +1 @@ +0xc8 diff --git a/test/fixtures/json5/numbers/hexadecimal-uppercase-x.json5 b/test/fixtures/json5/numbers/hexadecimal-uppercase-x.json5 new file mode 100644 index 00000000..1a35066b --- /dev/null +++ b/test/fixtures/json5/numbers/hexadecimal-uppercase-x.json5 @@ -0,0 +1 @@ +0XC8 diff --git a/test/fixtures/json5/numbers/hexadecimal-with-integer-exponent.json5 b/test/fixtures/json5/numbers/hexadecimal-with-integer-exponent.json5 new file mode 100644 index 00000000..3c2204af --- /dev/null +++ b/test/fixtures/json5/numbers/hexadecimal-with-integer-exponent.json5 @@ -0,0 +1 @@ +0xc8e4 diff --git a/test/fixtures/json5/numbers/hexadecimal.json5 b/test/fixtures/json5/numbers/hexadecimal.json5 new file mode 100644 index 00000000..cf832ed1 --- /dev/null +++ b/test/fixtures/json5/numbers/hexadecimal.json5 @@ -0,0 +1 @@ +0xC8 diff --git a/test/fixtures/json5/numbers/infinity.json5 b/test/fixtures/json5/numbers/infinity.json5 new file mode 100644 index 00000000..3c62151d --- /dev/null +++ b/test/fixtures/json5/numbers/infinity.json5 @@ -0,0 +1 @@ +Infinity diff --git a/test/fixtures/json5/numbers/integer-with-float-exponent.txt b/test/fixtures/json5/numbers/integer-with-float-exponent.txt new file mode 100644 index 00000000..fa0688c9 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-float-exponent.txt @@ -0,0 +1 @@ +1e2.3 diff --git a/test/fixtures/json5/numbers/integer-with-hexadecimal-exponent.txt b/test/fixtures/json5/numbers/integer-with-hexadecimal-exponent.txt new file mode 100644 index 00000000..0f58237d --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-hexadecimal-exponent.txt @@ -0,0 +1 @@ +1e0x4 diff --git a/test/fixtures/json5/numbers/integer-with-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-integer-exponent.json new file mode 100644 index 00000000..0d5cde84 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-integer-exponent.json @@ -0,0 +1 @@ +2e23 diff --git a/test/fixtures/json5/numbers/integer-with-negative-float-exponent.txt b/test/fixtures/json5/numbers/integer-with-negative-float-exponent.txt new file mode 100644 index 00000000..5be09158 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-negative-float-exponent.txt @@ -0,0 +1 @@ +1e-2.3 diff --git a/test/fixtures/json5/numbers/integer-with-negative-hexadecimal-exponent.txt b/test/fixtures/json5/numbers/integer-with-negative-hexadecimal-exponent.txt new file mode 100644 index 00000000..adeb2b98 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-negative-hexadecimal-exponent.txt @@ -0,0 +1 @@ +1e-0x4 diff --git a/test/fixtures/json5/numbers/integer-with-negative-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-negative-integer-exponent.json new file mode 100644 index 00000000..6118c3ec --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-negative-integer-exponent.json @@ -0,0 +1 @@ +2e-23 diff --git a/test/fixtures/json5/numbers/integer-with-negative-zero-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-negative-zero-integer-exponent.json new file mode 100644 index 00000000..eb67bf46 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-negative-zero-integer-exponent.json @@ -0,0 +1 @@ +5e-0 diff --git a/test/fixtures/json5/numbers/integer-with-positive-float-exponent.txt b/test/fixtures/json5/numbers/integer-with-positive-float-exponent.txt new file mode 100644 index 00000000..f89d55ec --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-positive-float-exponent.txt @@ -0,0 +1 @@ +1e+2.3 diff --git a/test/fixtures/json5/numbers/integer-with-positive-hexadecimal-exponent.txt b/test/fixtures/json5/numbers/integer-with-positive-hexadecimal-exponent.txt new file mode 100644 index 00000000..a6c75d94 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-positive-hexadecimal-exponent.txt @@ -0,0 +1 @@ +1e+0x4 diff --git a/test/fixtures/json5/numbers/integer-with-positive-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-positive-integer-exponent.json new file mode 100644 index 00000000..90c0616f --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-positive-integer-exponent.json @@ -0,0 +1 @@ +1e+2 diff --git a/test/fixtures/json5/numbers/integer-with-positive-zero-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-positive-zero-integer-exponent.json new file mode 100644 index 00000000..1d7002f9 --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-positive-zero-integer-exponent.json @@ -0,0 +1 @@ +5e+0 diff --git a/test/fixtures/json5/numbers/integer-with-zero-integer-exponent.json b/test/fixtures/json5/numbers/integer-with-zero-integer-exponent.json new file mode 100644 index 00000000..a5e3196e --- /dev/null +++ b/test/fixtures/json5/numbers/integer-with-zero-integer-exponent.json @@ -0,0 +1 @@ +5e0 diff --git a/test/fixtures/json5/numbers/integer.json b/test/fixtures/json5/numbers/integer.json new file mode 100644 index 00000000..60d3b2f4 --- /dev/null +++ b/test/fixtures/json5/numbers/integer.json @@ -0,0 +1 @@ +15 diff --git a/test/fixtures/json5/numbers/lone-decimal-point.txt b/test/fixtures/json5/numbers/lone-decimal-point.txt new file mode 100644 index 00000000..9c558e35 --- /dev/null +++ b/test/fixtures/json5/numbers/lone-decimal-point.txt @@ -0,0 +1 @@ +. diff --git a/test/fixtures/json5/numbers/nan.json5 b/test/fixtures/json5/numbers/nan.json5 new file mode 100644 index 00000000..736991a1 --- /dev/null +++ b/test/fixtures/json5/numbers/nan.json5 @@ -0,0 +1 @@ +NaN diff --git a/test/fixtures/json5/numbers/negative-float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/negative-float-leading-decimal-point.json5 new file mode 100644 index 00000000..c6eaee5c --- /dev/null +++ b/test/fixtures/json5/numbers/negative-float-leading-decimal-point.json5 @@ -0,0 +1 @@ +-.5 diff --git a/test/fixtures/json5/numbers/negative-float-leading-zero.json b/test/fixtures/json5/numbers/negative-float-leading-zero.json new file mode 100644 index 00000000..e118203f --- /dev/null +++ b/test/fixtures/json5/numbers/negative-float-leading-zero.json @@ -0,0 +1 @@ +-0.5 diff --git a/test/fixtures/json5/numbers/negative-float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/negative-float-trailing-decimal-point.json5 new file mode 100644 index 00000000..52e52459 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-float-trailing-decimal-point.json5 @@ -0,0 +1 @@ +-5. diff --git a/test/fixtures/json5/numbers/negative-float.json b/test/fixtures/json5/numbers/negative-float.json new file mode 100644 index 00000000..1d94c8a0 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-float.json @@ -0,0 +1 @@ +-1.2 diff --git a/test/fixtures/json5/numbers/negative-hexadecimal.json5 b/test/fixtures/json5/numbers/negative-hexadecimal.json5 new file mode 100644 index 00000000..8882fae3 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-hexadecimal.json5 @@ -0,0 +1 @@ +-0xC8 diff --git a/test/fixtures/json5/numbers/negative-infinity.json5 b/test/fixtures/json5/numbers/negative-infinity.json5 new file mode 100644 index 00000000..879e80ee --- /dev/null +++ b/test/fixtures/json5/numbers/negative-infinity.json5 @@ -0,0 +1 @@ +-Infinity diff --git a/test/fixtures/json5/numbers/negative-integer.json b/test/fixtures/json5/numbers/negative-integer.json new file mode 100644 index 00000000..21922364 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-integer.json @@ -0,0 +1 @@ +-15 diff --git a/test/fixtures/json5/numbers/negative-noctal.js b/test/fixtures/json5/numbers/negative-noctal.js new file mode 100644 index 00000000..8826f486 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-noctal.js @@ -0,0 +1 @@ +-098 diff --git a/test/fixtures/json5/numbers/negative-octal.txt b/test/fixtures/json5/numbers/negative-octal.txt new file mode 100644 index 00000000..2e7a4b45 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-octal.txt @@ -0,0 +1 @@ +-0123 diff --git a/test/fixtures/json5/numbers/negative-zero-float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/negative-zero-float-leading-decimal-point.json5 new file mode 100644 index 00000000..8dd8e037 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-float-leading-decimal-point.json5 @@ -0,0 +1 @@ +-.0 diff --git a/test/fixtures/json5/numbers/negative-zero-float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/negative-zero-float-trailing-decimal-point.json5 new file mode 100644 index 00000000..90cc048c --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-float-trailing-decimal-point.json5 @@ -0,0 +1 @@ +-0. diff --git a/test/fixtures/json5/numbers/negative-zero-float.json b/test/fixtures/json5/numbers/negative-zero-float.json new file mode 100644 index 00000000..1344bfd9 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-float.json @@ -0,0 +1 @@ +-0.0 diff --git a/test/fixtures/json5/numbers/negative-zero-hexadecimal.json5 b/test/fixtures/json5/numbers/negative-zero-hexadecimal.json5 new file mode 100644 index 00000000..8847d052 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-hexadecimal.json5 @@ -0,0 +1 @@ +-0x0 diff --git a/test/fixtures/json5/numbers/negative-zero-integer.json b/test/fixtures/json5/numbers/negative-zero-integer.json new file mode 100644 index 00000000..ec064f61 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-integer.json @@ -0,0 +1 @@ +-0 diff --git a/test/fixtures/json5/numbers/negative-zero-octal.txt b/test/fixtures/json5/numbers/negative-zero-octal.txt new file mode 100644 index 00000000..200a8018 --- /dev/null +++ b/test/fixtures/json5/numbers/negative-zero-octal.txt @@ -0,0 +1 @@ +-00 diff --git a/test/fixtures/json5/numbers/noctal-with-leading-octal-digit.js b/test/fixtures/json5/numbers/noctal-with-leading-octal-digit.js new file mode 100644 index 00000000..1fd7c08c --- /dev/null +++ b/test/fixtures/json5/numbers/noctal-with-leading-octal-digit.js @@ -0,0 +1 @@ +0780 diff --git a/test/fixtures/json5/numbers/noctal.js b/test/fixtures/json5/numbers/noctal.js new file mode 100644 index 00000000..fa5c7835 --- /dev/null +++ b/test/fixtures/json5/numbers/noctal.js @@ -0,0 +1 @@ +080 diff --git a/test/fixtures/json5/numbers/octal.txt b/test/fixtures/json5/numbers/octal.txt new file mode 100644 index 00000000..9e8493ea --- /dev/null +++ b/test/fixtures/json5/numbers/octal.txt @@ -0,0 +1 @@ +010 diff --git a/test/fixtures/json5/numbers/positive-float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/positive-float-leading-decimal-point.json5 new file mode 100644 index 00000000..04346080 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-float-leading-decimal-point.json5 @@ -0,0 +1 @@ ++.5 diff --git a/test/fixtures/json5/numbers/positive-float-leading-zero.json5 b/test/fixtures/json5/numbers/positive-float-leading-zero.json5 new file mode 100644 index 00000000..d89b45d1 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-float-leading-zero.json5 @@ -0,0 +1 @@ ++0.5 diff --git a/test/fixtures/json5/numbers/positive-float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/positive-float-trailing-decimal-point.json5 new file mode 100644 index 00000000..bee758a7 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-float-trailing-decimal-point.json5 @@ -0,0 +1 @@ ++5. diff --git a/test/fixtures/json5/numbers/positive-float.json5 b/test/fixtures/json5/numbers/positive-float.json5 new file mode 100644 index 00000000..c5732cbc --- /dev/null +++ b/test/fixtures/json5/numbers/positive-float.json5 @@ -0,0 +1 @@ ++1.2 diff --git a/test/fixtures/json5/numbers/positive-hexadecimal.json5 b/test/fixtures/json5/numbers/positive-hexadecimal.json5 new file mode 100644 index 00000000..c91ede96 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-hexadecimal.json5 @@ -0,0 +1 @@ ++0xC8 diff --git a/test/fixtures/json5/numbers/positive-infinity.json5 b/test/fixtures/json5/numbers/positive-infinity.json5 new file mode 100644 index 00000000..9bcb989f --- /dev/null +++ b/test/fixtures/json5/numbers/positive-infinity.json5 @@ -0,0 +1 @@ ++Infinity diff --git a/test/fixtures/json5/numbers/positive-integer.json5 b/test/fixtures/json5/numbers/positive-integer.json5 new file mode 100644 index 00000000..8ed01e07 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-integer.json5 @@ -0,0 +1 @@ ++15 diff --git a/test/fixtures/json5/numbers/positive-noctal.js b/test/fixtures/json5/numbers/positive-noctal.js new file mode 100644 index 00000000..2f450fce --- /dev/null +++ b/test/fixtures/json5/numbers/positive-noctal.js @@ -0,0 +1 @@ ++098 diff --git a/test/fixtures/json5/numbers/positive-octal.txt b/test/fixtures/json5/numbers/positive-octal.txt new file mode 100644 index 00000000..faa86009 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-octal.txt @@ -0,0 +1 @@ ++0123 diff --git a/test/fixtures/json5/numbers/positive-zero-float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/positive-zero-float-leading-decimal-point.json5 new file mode 100644 index 00000000..557bcde1 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-float-leading-decimal-point.json5 @@ -0,0 +1 @@ ++.0 diff --git a/test/fixtures/json5/numbers/positive-zero-float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/positive-zero-float-trailing-decimal-point.json5 new file mode 100644 index 00000000..d8912d16 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-float-trailing-decimal-point.json5 @@ -0,0 +1 @@ ++0. diff --git a/test/fixtures/json5/numbers/positive-zero-float.json5 b/test/fixtures/json5/numbers/positive-zero-float.json5 new file mode 100644 index 00000000..11e8402c --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-float.json5 @@ -0,0 +1 @@ ++0.0 diff --git a/test/fixtures/json5/numbers/positive-zero-hexadecimal.json5 b/test/fixtures/json5/numbers/positive-zero-hexadecimal.json5 new file mode 100644 index 00000000..40a9ce63 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-hexadecimal.json5 @@ -0,0 +1 @@ ++0x0 diff --git a/test/fixtures/json5/numbers/positive-zero-integer.json5 b/test/fixtures/json5/numbers/positive-zero-integer.json5 new file mode 100644 index 00000000..9317bcb6 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-integer.json5 @@ -0,0 +1 @@ ++0 diff --git a/test/fixtures/json5/numbers/positive-zero-octal.txt b/test/fixtures/json5/numbers/positive-zero-octal.txt new file mode 100644 index 00000000..80959e57 --- /dev/null +++ b/test/fixtures/json5/numbers/positive-zero-octal.txt @@ -0,0 +1 @@ ++00 diff --git a/test/fixtures/json5/numbers/zero-float-leading-decimal-point.json5 b/test/fixtures/json5/numbers/zero-float-leading-decimal-point.json5 new file mode 100644 index 00000000..7d856fdb --- /dev/null +++ b/test/fixtures/json5/numbers/zero-float-leading-decimal-point.json5 @@ -0,0 +1 @@ +.0 diff --git a/test/fixtures/json5/numbers/zero-float-trailing-decimal-point.json5 b/test/fixtures/json5/numbers/zero-float-trailing-decimal-point.json5 new file mode 100644 index 00000000..17a5757b --- /dev/null +++ b/test/fixtures/json5/numbers/zero-float-trailing-decimal-point.json5 @@ -0,0 +1 @@ +0. diff --git a/test/fixtures/json5/numbers/zero-float.json b/test/fixtures/json5/numbers/zero-float.json new file mode 100644 index 00000000..ba66466c --- /dev/null +++ b/test/fixtures/json5/numbers/zero-float.json @@ -0,0 +1 @@ +0.0 diff --git a/test/fixtures/json5/numbers/zero-hexadecimal.json5 b/test/fixtures/json5/numbers/zero-hexadecimal.json5 new file mode 100644 index 00000000..9982566d --- /dev/null +++ b/test/fixtures/json5/numbers/zero-hexadecimal.json5 @@ -0,0 +1 @@ +0x0 diff --git a/test/fixtures/json5/numbers/zero-integer-with-integer-exponent.json b/test/fixtures/json5/numbers/zero-integer-with-integer-exponent.json new file mode 100644 index 00000000..da219e3f --- /dev/null +++ b/test/fixtures/json5/numbers/zero-integer-with-integer-exponent.json @@ -0,0 +1 @@ +0e23 diff --git a/test/fixtures/json5/numbers/zero-integer.json b/test/fixtures/json5/numbers/zero-integer.json new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/test/fixtures/json5/numbers/zero-integer.json @@ -0,0 +1 @@ +0 diff --git a/test/fixtures/json5/numbers/zero-octal.txt b/test/fixtures/json5/numbers/zero-octal.txt new file mode 100644 index 00000000..4daddb72 --- /dev/null +++ b/test/fixtures/json5/numbers/zero-octal.txt @@ -0,0 +1 @@ +00 diff --git a/test/fixtures/json5/objects/duplicate-keys.json b/test/fixtures/json5/objects/duplicate-keys.json new file mode 100644 index 00000000..bb0e4cc3 --- /dev/null +++ b/test/fixtures/json5/objects/duplicate-keys.json @@ -0,0 +1,4 @@ +{ + "a": true, + "a": false +} diff --git a/test/fixtures/json5/objects/empty-object.json b/test/fixtures/json5/objects/empty-object.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/test/fixtures/json5/objects/empty-object.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/fixtures/json5/objects/illegal-unquoted-key-number.errorSpec b/test/fixtures/json5/objects/illegal-unquoted-key-number.errorSpec new file mode 100644 index 00000000..e44dc850 --- /dev/null +++ b/test/fixtures/json5/objects/illegal-unquoted-key-number.errorSpec @@ -0,0 +1,6 @@ +{ + at: 7, + lineNumber: 2, + columnNumber: 5, + message: "Bad identifier as unquoted key" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/illegal-unquoted-key-number.txt b/test/fixtures/json5/objects/illegal-unquoted-key-number.txt new file mode 100644 index 00000000..aebcac2c --- /dev/null +++ b/test/fixtures/json5/objects/illegal-unquoted-key-number.txt @@ -0,0 +1,3 @@ +{ + 10twenty: "ten twenty" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/illegal-unquoted-key-symbol.errorSpec b/test/fixtures/json5/objects/illegal-unquoted-key-symbol.errorSpec new file mode 100644 index 00000000..95ba4683 --- /dev/null +++ b/test/fixtures/json5/objects/illegal-unquoted-key-symbol.errorSpec @@ -0,0 +1,6 @@ +{ + at: 12, + lineNumber: 2, + columnNumber: 10, + message: "Expected ':' instead of '-'" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/illegal-unquoted-key-symbol.txt b/test/fixtures/json5/objects/illegal-unquoted-key-symbol.txt new file mode 100644 index 00000000..4cb2bd5c --- /dev/null +++ b/test/fixtures/json5/objects/illegal-unquoted-key-symbol.txt @@ -0,0 +1,3 @@ +{ + multi-word: "multi-word" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/leading-comma-object.errorSpec b/test/fixtures/json5/objects/leading-comma-object.errorSpec new file mode 100644 index 00000000..e44dc850 --- /dev/null +++ b/test/fixtures/json5/objects/leading-comma-object.errorSpec @@ -0,0 +1,6 @@ +{ + at: 7, + lineNumber: 2, + columnNumber: 5, + message: "Bad identifier as unquoted key" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/leading-comma-object.txt b/test/fixtures/json5/objects/leading-comma-object.txt new file mode 100644 index 00000000..bfb3c51f --- /dev/null +++ b/test/fixtures/json5/objects/leading-comma-object.txt @@ -0,0 +1,3 @@ +{ + ,"foo": "bar" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/lone-trailing-comma-object.txt b/test/fixtures/json5/objects/lone-trailing-comma-object.txt new file mode 100644 index 00000000..3f3f9f79 --- /dev/null +++ b/test/fixtures/json5/objects/lone-trailing-comma-object.txt @@ -0,0 +1,3 @@ +{ + , +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/no-comma-object.txt b/test/fixtures/json5/objects/no-comma-object.txt new file mode 100644 index 00000000..c0738750 --- /dev/null +++ b/test/fixtures/json5/objects/no-comma-object.txt @@ -0,0 +1,4 @@ +{ + "foo": "bar" + "hello": "world" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/reserved-unquoted-key.json5 b/test/fixtures/json5/objects/reserved-unquoted-key.json5 new file mode 100644 index 00000000..4b80a63b --- /dev/null +++ b/test/fixtures/json5/objects/reserved-unquoted-key.json5 @@ -0,0 +1,3 @@ +{ + while: true +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/single-quoted-key.json5 b/test/fixtures/json5/objects/single-quoted-key.json5 new file mode 100644 index 00000000..842ca19c --- /dev/null +++ b/test/fixtures/json5/objects/single-quoted-key.json5 @@ -0,0 +1,3 @@ +{ + 'hello': "world" +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/trailing-comma-object.json5 b/test/fixtures/json5/objects/trailing-comma-object.json5 new file mode 100644 index 00000000..ab61ba76 --- /dev/null +++ b/test/fixtures/json5/objects/trailing-comma-object.json5 @@ -0,0 +1,3 @@ +{ + "foo": "bar", +} \ No newline at end of file diff --git a/test/fixtures/json5/objects/unquoted-keys.json5 b/test/fixtures/json5/objects/unquoted-keys.json5 new file mode 100644 index 00000000..0c06f3fc --- /dev/null +++ b/test/fixtures/json5/objects/unquoted-keys.json5 @@ -0,0 +1,8 @@ +{ + hello: "world", + _: "underscore", + $: "dollar sign", + one1: "numerals", + _$_: "multiple symbols", + $_$hello123world_$_: "mixed" +} \ No newline at end of file diff --git a/test/fixtures/json5/strings/escaped-single-quoted-string.json5 b/test/fixtures/json5/strings/escaped-single-quoted-string.json5 new file mode 100644 index 00000000..1c799101 --- /dev/null +++ b/test/fixtures/json5/strings/escaped-single-quoted-string.json5 @@ -0,0 +1 @@ +'I can\'t wait' \ No newline at end of file diff --git a/test/fixtures/json5/strings/multi-line-string.json5 b/test/fixtures/json5/strings/multi-line-string.json5 new file mode 100644 index 00000000..964dc2de --- /dev/null +++ b/test/fixtures/json5/strings/multi-line-string.json5 @@ -0,0 +1,2 @@ +'hello\ + world' \ No newline at end of file diff --git a/test/fixtures/json5/strings/no-comma-array.errorSpec b/test/fixtures/json5/strings/no-comma-array.errorSpec new file mode 100644 index 00000000..98355610 --- /dev/null +++ b/test/fixtures/json5/strings/no-comma-array.errorSpec @@ -0,0 +1,6 @@ +{ + at: 16, + lineNumber: 3, + columNumber: 5, + message: "Expected ']' instead of 'f'" +} \ No newline at end of file diff --git a/test/fixtures/json5/strings/single-quoted-string.json5 b/test/fixtures/json5/strings/single-quoted-string.json5 new file mode 100644 index 00000000..5dadd333 --- /dev/null +++ b/test/fixtures/json5/strings/single-quoted-string.json5 @@ -0,0 +1 @@ +'hello world' \ No newline at end of file diff --git a/test/fixtures/json5/strings/unescaped-multi-line-string.errorSpec b/test/fixtures/json5/strings/unescaped-multi-line-string.errorSpec new file mode 100644 index 00000000..a85f1ad1 --- /dev/null +++ b/test/fixtures/json5/strings/unescaped-multi-line-string.errorSpec @@ -0,0 +1,6 @@ +{ + at: 5, + lineNumber: 2, + columnNumber: 0, + message: "Bad string" +} \ No newline at end of file diff --git a/test/fixtures/json5/strings/unescaped-multi-line-string.txt b/test/fixtures/json5/strings/unescaped-multi-line-string.txt new file mode 100644 index 00000000..7325139a --- /dev/null +++ b/test/fixtures/json5/strings/unescaped-multi-line-string.txt @@ -0,0 +1,2 @@ +"foo +bar" diff --git a/test/fixtures/json5/todo/unicode-escaped-unquoted-key.json5 b/test/fixtures/json5/todo/unicode-escaped-unquoted-key.json5 new file mode 100644 index 00000000..56c34571 --- /dev/null +++ b/test/fixtures/json5/todo/unicode-escaped-unquoted-key.json5 @@ -0,0 +1,3 @@ +{ + sig\u03A3ma: "the sum of all things" +} \ No newline at end of file diff --git a/test/fixtures/json5/todo/unicode-unquoted-key.json5 b/test/fixtures/json5/todo/unicode-unquoted-key.json5 new file mode 100644 index 00000000..98382e69 --- /dev/null +++ b/test/fixtures/json5/todo/unicode-unquoted-key.json5 @@ -0,0 +1,3 @@ +{ + ümlåût: "that's not really an ümlaüt, but this is" +} \ No newline at end of file diff --git a/test/todo/json5.js b/test/todo/json5.js new file mode 100644 index 00000000..fbb38bea --- /dev/null +++ b/test/todo/json5.js @@ -0,0 +1,81 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const tap = require('tap'); +const jstp = require('../..'); + +const supportedByUs = { + arrays: [ + 'leading-comma-array', + 'lone-trailing-comma-array' + ], + numbers: [ + 'negative-noctal', + 'noctal-with-leading-octal-digit', + 'noctal', + 'positive-noctal' + ] +}; + +// Parses a JavaScript object, and if it's a sparse array, +// converts it to a dense one. +function extendedEval(source) { + const obj = eval(`(${source}\n)`); + if (Array.isArray(obj)) { + for (let index = 0; index < obj.length; index++) { + if (!(index in obj)) { + obj[index] = undefined; + } + } + } + return obj; +} + +const testCasesPath = path.resolve(__dirname, '../fixtures/json5'); +const testCases = fs.readdirSync(testCasesPath) + .map(caseName => ({ + name: caseName, + path: path.join(testCasesPath, caseName) + })) + .filter(testCase => fs.statSync(testCase.path).isDirectory()); + +testCases.forEach((testCase) => { + tap.test(testCase.name, (test) => { + fs.readdirSync(testCase.path).forEach((filename) => { + const ext = path.extname(filename); + if (!['.json', '.json5', '.js', '.txt'].includes(ext)) { + return; + } + + const testName = path.basename(filename, ext); + const testPath = path.join(testCase.path, filename); + const file = fs.readFileSync(testPath, 'utf8'); + + test.test(testName, (test) => { + switch (ext) { + case '.json': + test.strictSame(jstp.parse(file), JSON.parse(file)); + break; + case '.json5': + test.strictSame(jstp.parse(file), extendedEval(file)); + break; + case '.js': { + const supportedTests = supportedByUs[testCase.name]; + if (supportedTests && supportedTests.includes(testName)) { + test.strictSame(jstp.parse(file), extendedEval(file)); + } else { + test.throws(() => jstp.parse(file)); + } + break; + } + case '.txt': + test.throws(() => jstp.parse(file)); + break; + } + test.end(); + }); + }); + test.end(); + }); +});