From 2f384ab24ad4d42390827ea46f178aab4503a2d2 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 2 Mar 2021 13:43:48 +0800 Subject: [PATCH] JSON: More JSON5 data tests (#10453) --- .../json/__snapshots__/jsfmt.spec.js.snap | 456 ++++++++++++------ tests/json/json/json5.json | 25 + tests/json/json/numbers.json | 11 - 3 files changed, 325 insertions(+), 167 deletions(-) create mode 100644 tests/json/json/json5.json delete mode 100644 tests/json/json/numbers.json diff --git a/tests/json/json/__snapshots__/jsfmt.spec.js.snap b/tests/json/json/__snapshots__/jsfmt.spec.js.snap index 31e7f1547..053de007c 100644 --- a/tests/json/json/__snapshots__/jsfmt.spec.js.snap +++ b/tests/json/json/__snapshots__/jsfmt.spec.js.snap @@ -205,6 +205,306 @@ true ================================================================================ `; +exports[`json5.json - {"trailingComma":"all"} format 1`] = ` +====================================options===================================== +parsers: ["json"] +printWidth: 80 +trailingComma: "all" + | printWidth +=====================================input====================================== +[ +{ + '//': 'JSON5 allow \`Infinity\` and \`NaN\`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", +} +] + +=====================================output===================================== +[ + { + "//": "JSON5 allow \`Infinity\` and \`NaN\`", + "numbers": [Infinity, -Infinity, NaN], + "Infinity": NaN, + "NaN": Infinity, + "NaN": -Infinity + }, + { + "//": "JSON5 numbers", + "hexadecimal": 0xdecaf, + "leadingDecimalPoint": 0.8675309, + "andTrailing": 8675309, + "positiveSign": +1 + }, + { + "//": "JSON5 strings", + "singleQuotes": "I can use \\"double quotes\\" here", + "lineBreaks": "Look, Mom! \\ +No \\\\n's!" + } +] + +================================================================================ +`; + +exports[`json5.json - {"trailingComma":"all"} format 2`] = ` +====================================options===================================== +parsers: ["json5"] +printWidth: 80 +trailingComma: "all" + | printWidth +=====================================input====================================== +[ +{ + '//': 'JSON5 allow \`Infinity\` and \`NaN\`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", +} +] + +=====================================output===================================== +[ + { + "//": "JSON5 allow \`Infinity\` and \`NaN\`", + numbers: [Infinity, -Infinity, NaN], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, + }, + { + "//": "JSON5 numbers", + hexadecimal: 0xdecaf, + leadingDecimalPoint: 0.8675309, + andTrailing: 8675309, + positiveSign: +1, + }, + { + "//": "JSON5 strings", + singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", + }, +] + +================================================================================ +`; + +exports[`json5.json format 1`] = ` +====================================options===================================== +parsers: ["json"] +printWidth: 80 + | printWidth +=====================================input====================================== +[ +{ + '//': 'JSON5 allow \`Infinity\` and \`NaN\`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", +} +] + +=====================================output===================================== +[ + { + "//": "JSON5 allow \`Infinity\` and \`NaN\`", + "numbers": [Infinity, -Infinity, NaN], + "Infinity": NaN, + "NaN": Infinity, + "NaN": -Infinity + }, + { + "//": "JSON5 numbers", + "hexadecimal": 0xdecaf, + "leadingDecimalPoint": 0.8675309, + "andTrailing": 8675309, + "positiveSign": +1 + }, + { + "//": "JSON5 strings", + "singleQuotes": "I can use \\"double quotes\\" here", + "lineBreaks": "Look, Mom! \\ +No \\\\n's!" + } +] + +================================================================================ +`; + +exports[`json5.json format 2`] = ` +====================================options===================================== +parsers: ["json5"] +printWidth: 80 + | printWidth +=====================================input====================================== +[ +{ + '//': 'JSON5 allow \`Infinity\` and \`NaN\`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", +} +] + +=====================================output===================================== +[ + { + "//": "JSON5 allow \`Infinity\` and \`NaN\`", + numbers: [Infinity, -Infinity, NaN], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, + }, + { + "//": "JSON5 numbers", + hexadecimal: 0xdecaf, + leadingDecimalPoint: 0.8675309, + andTrailing: 8675309, + positiveSign: +1, + }, + { + "//": "JSON5 strings", + singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", + }, +] + +================================================================================ +`; + +exports[`json5.json format 3`] = ` +====================================options===================================== +parsers: ["json-stringify"] +printWidth: 80 + | printWidth +=====================================input====================================== +[ +{ + '//': 'JSON5 allow \`Infinity\` and \`NaN\`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \\ +No \\\\n's!", +} +] + +=====================================output===================================== +[ + { + "//": "JSON5 allow \`Infinity\` and \`NaN\`", + "numbers": [ + Infinity, + -Infinity, + NaN + ], + "Infinity": NaN, + "NaN": Infinity, + "NaN": -Infinity + }, + { + "//": "JSON5 numbers", + "hexadecimal": 912559, + "leadingDecimalPoint": 0.8675309, + "andTrailing": 8675309, + "positiveSign": 1 + }, + { + "//": "JSON5 strings", + "singleQuotes": "I can use \\"double quotes\\" here", + "lineBreaks": "Look, Mom! No \\\\n's!" + } +] + +================================================================================ +`; + exports[`key-value.json - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["json"] @@ -553,162 +853,6 @@ printWidth: 80 ================================================================================ `; -exports[`numbers.json - {"trailingComma":"all"} format 1`] = ` -====================================options===================================== -parsers: ["json"] -printWidth: 80 -trailingComma: "all" - | printWidth -=====================================input====================================== -{ - '//': 'JSON5 allow \`Infinity\` and \`NaN\`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -=====================================output===================================== -{ - "//": "JSON5 allow \`Infinity\` and \`NaN\`", - "numbers": [Infinity, -Infinity, NaN], - "Infinity": NaN, - "NaN": Infinity, - "NaN": -Infinity -} - -================================================================================ -`; - -exports[`numbers.json - {"trailingComma":"all"} format 2`] = ` -====================================options===================================== -parsers: ["json5"] -printWidth: 80 -trailingComma: "all" - | printWidth -=====================================input====================================== -{ - '//': 'JSON5 allow \`Infinity\` and \`NaN\`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -=====================================output===================================== -{ - "//": "JSON5 allow \`Infinity\` and \`NaN\`", - numbers: [Infinity, -Infinity, NaN], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -================================================================================ -`; - -exports[`numbers.json format 1`] = ` -====================================options===================================== -parsers: ["json"] -printWidth: 80 - | printWidth -=====================================input====================================== -{ - '//': 'JSON5 allow \`Infinity\` and \`NaN\`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -=====================================output===================================== -{ - "//": "JSON5 allow \`Infinity\` and \`NaN\`", - "numbers": [Infinity, -Infinity, NaN], - "Infinity": NaN, - "NaN": Infinity, - "NaN": -Infinity -} - -================================================================================ -`; - -exports[`numbers.json format 2`] = ` -====================================options===================================== -parsers: ["json5"] -printWidth: 80 - | printWidth -=====================================input====================================== -{ - '//': 'JSON5 allow \`Infinity\` and \`NaN\`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -=====================================output===================================== -{ - "//": "JSON5 allow \`Infinity\` and \`NaN\`", - numbers: [Infinity, -Infinity, NaN], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -================================================================================ -`; - -exports[`numbers.json format 3`] = ` -====================================options===================================== -parsers: ["json-stringify"] -printWidth: 80 - | printWidth -=====================================input====================================== -{ - '//': 'JSON5 allow \`Infinity\` and \`NaN\`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -} - -=====================================output===================================== -{ - "//": "JSON5 allow \`Infinity\` and \`NaN\`", - "numbers": [ - Infinity, - -Infinity, - NaN - ], - "Infinity": NaN, - "NaN": Infinity, - "NaN": -Infinity -} - -================================================================================ -`; - exports[`pass1.json - {"trailingComma":"all"} format 1`] = ` ====================================options===================================== parsers: ["json"] diff --git a/tests/json/json/json5.json b/tests/json/json/json5.json new file mode 100644 index 000000000..795b5b069 --- /dev/null +++ b/tests/json/json/json5.json @@ -0,0 +1,25 @@ +[ +{ + '//': 'JSON5 allow `Infinity` and `NaN`', + numbers: [ + Infinity, + -Infinity, + NaN, + ], + Infinity: NaN, + NaN: Infinity, + NaN: -Infinity, +}, +{ + '//': 'JSON5 numbers', + hexadecimal: 0xdecaf, + leadingDecimalPoint: .8675309, andTrailing: 8675309., + positiveSign: +1, +}, +{ + '//': 'JSON5 strings', +singleQuotes: 'I can use "double quotes" here', + lineBreaks: "Look, Mom! \ +No \\n's!", +} +] diff --git a/tests/json/json/numbers.json b/tests/json/json/numbers.json deleted file mode 100644 index 5bde5d67d..000000000 --- a/tests/json/json/numbers.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - '//': 'JSON5 allow `Infinity` and `NaN`', - numbers: [ - Infinity, - -Infinity, - NaN, - ], - Infinity: NaN, - NaN: Infinity, - NaN: -Infinity, -}