Skip to content

Commit

Permalink
test: add JSON5 specs test suite
Browse files Browse the repository at this point in the history
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: metarhia/jstp#158
Refs: https://github.com/metarhia/JSTP/issues/152
Reviewed-By: Dmytro Nechai <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Mykola Bilochub <[email protected]>
  • Loading branch information
aqrln authored and belochub committed Jul 21, 2018
1 parent af9905a commit 52f8723
Show file tree
Hide file tree
Showing 127 changed files with 629 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
dist/
site/
examples/data-formats/*.js
test/fixtures/json5/**/*.js
21 changes: 21 additions & 0 deletions test/fixtures/json5/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions test/fixtures/json5/README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions test/fixtures/json5/arrays/empty-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions test/fixtures/json5/arrays/leading-comma-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
,null
]
3 changes: 3 additions & 0 deletions test/fixtures/json5/arrays/lone-trailing-comma-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
,
]
6 changes: 6 additions & 0 deletions test/fixtures/json5/arrays/no-comma-array.errorSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
at: 16,
lineNumber: 3,
columnNumber: 5,
message: "Expected ']' instead of 'f'"
}
4 changes: 4 additions & 0 deletions test/fixtures/json5/arrays/no-comma-array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
true
false
]
5 changes: 5 additions & 0 deletions test/fixtures/json5/arrays/regular-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
true,
false,
null
]
3 changes: 3 additions & 0 deletions test/fixtures/json5/arrays/trailing-comma-array.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
null,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
false
/*
true
*/
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
null
/*
Some non-comment top-level value is needed;
we use null above.
*/
1 change: 1 addition & 0 deletions test/fixtures/json5/comments/block-comment-in-string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"This /* block comment */ isn't really a block comment."
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
Some non-comment top-level value is needed;
we use null below.
*/
null
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
false // true
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null // Some non-comment top-level value is needed; we use null here.
1 change: 1 addition & 0 deletions test/fixtures/json5/comments/inline-comment-in-string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"This inline comment // isn't really an inline comment."
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Some non-comment top-level value is needed; we use null below.
null
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
at: 77,
lineNumber: 4,
columnNumber: 3,
message: "Unexpected EOF"
}
4 changes: 4 additions & 0 deletions test/fixtures/json5/comments/top-level-block-comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
This should fail;
comments cannot be the only top-level value.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
at: 66,
lineNumber: 1,
columnNumber: 67,
message: "Unexpected EOF"
}
1 change: 1 addition & 0 deletions test/fixtures/json5/comments/top-level-inline-comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This should fail; comments cannot be the only top-level value.
5 changes: 5 additions & 0 deletions test/fixtures/json5/comments/unterminated-block-comment.txt
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
106 changes: 106 additions & 0 deletions test/fixtures/json5/misc/npm-package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (http://blog.izs.me)",
"repository": {
"type": "git",
"url": "https://github.com/isaacs/npm"
},
"bugs": {
"email": "[email protected]",
"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"
}
]
}
106 changes: 106 additions & 0 deletions test/fixtures/json5/misc/npm-package.json5
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (http://blog.izs.me)',
repository: {
type: 'git',
url: 'https://github.com/isaacs/npm',
},
bugs: {
email: '[email protected]',
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',
},
],
}
Loading

0 comments on commit 52f8723

Please sign in to comment.