diff --git a/bin/jp-compliance b/bin/jp-compliance index 6baa0b6..5e0ac1d 100755 --- a/bin/jp-compliance +++ b/bin/jp-compliance @@ -196,7 +196,7 @@ class ComplianceTestRunner(object): failure_message = ( "\nFAIL {category},{group_number},{test_number}\n" "The expression: {expression}\n" - "was suppose to give: {result}\n" + "was supposed to give: {result}\n" "for the JSON: {given_js}\n" "but instead gave: {actual}\n" ).format(**test_case) @@ -208,7 +208,7 @@ class ComplianceTestRunner(object): failure_message = ( "\nFAIL {category},{group_number},{test_number}\n" "The expression: {expression}\n" - "was suppose to have non zero for error error: {error}\n" + "was supposed to have non zero for error error: {error}\n" "but instead gave rc of: {returncode}, stderr: \n{stderr}\n" ).format(**test_case) sys.stdout.write(failure_message) @@ -218,7 +218,7 @@ class ComplianceTestRunner(object): failure_message = ( "\nFAIL {category},{group_number},{test_number}\n" "The expression: {expression}\n" - "was suppose to emit the error: {error}\n" + "was supposed to emit the error: {error}\n" "but instead gave: \n{stderr}\n" ).format(**test_case) sys.stdout.write(failure_message) diff --git a/tests/jep-12/jep-12-literal.json b/tests/jep-12/jep-12-literal.json new file mode 100644 index 0000000..40cdd53 --- /dev/null +++ b/tests/jep-12/jep-12-literal.json @@ -0,0 +1,39 @@ +[ + { + "comment": "Literals", + "given": { + "type": "object" + }, + "cases": [ + { + "expression": "`foo`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+0085 NEXT LINE", + "expression": "`0\u0085`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+00A0 NO-BREAK SPACE", + "expression": "`0\u00A0`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+1680 OGHAM SPACE MARK", + "expression": "`0\u1680`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+2028 LINE SEPARATOR", + "expression": "`0\u2028`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+3000 IDEOGRAPHIC SPACE", + "expression": "`0\u3000`", + "error": "syntax" + } + ] + } +] \ No newline at end of file diff --git a/tests/legacy/legacy-literal.json b/tests/legacy/legacy-literal.json new file mode 100644 index 0000000..8fd73b9 --- /dev/null +++ b/tests/legacy/legacy-literal.json @@ -0,0 +1,89 @@ +[ + { + "given": { + "foo": [ + { + "name": "a" + }, + { + "name": "b" + } + ], + "bar": { + "baz": "qux" + } + }, + "cases": [ + { + "expression": "`foo`", + "result": "foo" + }, + { + "comment": "Double quotes must be escaped.", + "expression": "`foo\\\"quote`", + "result": "foo\"quote" + }, + { + "expression": "`✓`", + "result": "✓" + }, + { + "expression": "`1\\``", + "result": "1`" + }, + { + "comment": "Multiple literal expressions with escapes", + "expression": "`\\\\`.{a:`b`}", + "result": { + "a": "b" + } + } + ] + }, + { + "comment": "Literals", + "given": { + "type": "object" + }, + "cases": [ + { + "expression": "`foo`", + "result": "foo" + }, + { + "expression": "` foo`", + "result": "foo" + }, + { + "comment": "Literal on RHS of subexpr not allowed", + "expression": "foo.`bar`", + "error": "syntax" + }, + { + "comment": "Literal with non-JSON whitespace U+0085 NEXT LINE", + "expression": "`0\u0085`", + "result": "0\u0085" + }, + { + "comment": "Literal with non-JSON whitespace U+00A0 NO-BREAK SPACE", + "expression": "`0\u00A0`", + "result": "0\u00A0" + }, + { + "comment": "Literal with non-JSON whitespace U+1680 OGHAM SPACE MARK", + "expression": "`0\u1680`", + "result": "0\u1680" + }, + { + "comment": "Literal with non-JSON whitespace U+2028 LINE SEPARATOR", + "expression": "`0\u2028`", + "result": "0\u2028" + }, + { + "comment": "Literal with non-JSON whitespace U+3000 IDEOGRAPHIC SPACE", + "expression": "`0\u3000`", + "result": "0\u3000" + } + ] + } +] \ No newline at end of file diff --git a/tests/literal.json b/tests/literal.json index b5ddbed..8c2d16f 100644 --- a/tests/literal.json +++ b/tests/literal.json @@ -1,200 +1,235 @@ [ - { - "given": { - "foo": [{"name": "a"}, {"name": "b"}], - "bar": {"baz": "qux"} - }, - "cases": [ - { - "expression": "`\"foo\"`", - "result": "foo" - }, - { - "comment": "Interpret escaped unicode.", - "expression": "`\"\\u03a6\"`", - "result": "Φ" - }, - { - "expression": "`\"✓\"`", - "result": "✓" - }, - { - "expression": "`[1, 2, 3]`", - "result": [1, 2, 3] - }, - { - "expression": "`{\"a\": \"b\"}`", - "result": {"a": "b"} - }, - { - "expression": "`true`", - "result": true - }, - { - "expression": "`false`", - "result": false - }, - { - "expression": "`null`", - "result": null - }, - { - "expression": "`0`", - "result": 0 - }, - { - "expression": "`1`", - "result": 1 - }, - { - "expression": "`2`", - "result": 2 - }, - { - "expression": "`3`", - "result": 3 - }, - { - "expression": "`4`", - "result": 4 - }, - { - "expression": "`5`", - "result": 5 - }, - { - "expression": "`6`", - "result": 6 - }, - { - "expression": "`7`", - "result": 7 - }, - { - "expression": "`8`", - "result": 8 - }, - { - "expression": "`9`", - "result": 9 - }, - { - "comment": "Escaping a backtick in quotes", - "expression": "`\"foo\\`bar\"`", - "result": "foo`bar" - }, - { - "comment": "Double quote in literal", - "expression": "`\"foo\\\"bar\"`", - "result": "foo\"bar" - }, - { - "expression": "`\"1\\`\"`", - "result": "1`" - }, - { - "comment": "Multiple literal expressions with escapes", - "expression": "`\"\\\\\"`.{a:`\"b\"`}", - "result": {"a": "b"} - }, - { - "comment": "literal . identifier", - "expression": "`{\"a\": \"b\"}`.a", - "result": "b" - }, - { - "comment": "literal . identifier . identifier", - "expression": "`{\"a\": {\"b\": \"c\"}}`.a.b", - "result": "c" - }, - { - "comment": "literal . identifier bracket-expr", - "expression": "`[0, 1, 2]`[1]", - "result": 1 - } - ] - }, - { - "comment": "Literals", - "given": {"type": "object"}, - "cases": [ - { - "comment": "Literal with leading whitespace", - "expression": "` {\"foo\": true}`", - "result": {"foo": true} - }, + { + "given": { + "foo": [ { - "comment": "Literal with trailing whitespace", - "expression": "`{\"foo\": true} `", - "result": {"foo": true} + "name": "a" }, { - "comment": "Literal on RHS of subexpr not allowed", - "expression": "foo.`\"bar\"`", - "error": "syntax" + "name": "b" } - ] + ], + "bar": { + "baz": "qux" + } }, - { - "comment": "Raw String Literals", - "given": {}, - "cases": [ - { - "expression": "'foo'", - "result": "foo" - }, - { - "expression": "' foo '", - "result": " foo " - }, - { - "expression": "'0'", - "result": "0" - }, - { - "expression": "'newline\n'", - "result": "newline\n" - }, - { - "expression": "'\n'", - "result": "\n" - }, - { - "expression": "'✓'", - "result": "✓" - }, - { - "expression": "'𝄞'", - "result": "𝄞" - }, - { - "expression": "' [foo] '", - "result": " [foo] " - }, - { - "expression": "'[foo]'", - "result": "[foo]" - }, - { - "comment": "Do not interpret escaped unicode.", - "expression": "'\\u03a6'", - "result": "\\u03a6" - }, - { - "comment": "Can escape the single quote", - "expression": "'foo\\'bar'", - "result": "foo'bar" - }, - { - "comment": "Backslash not followed by single quote is treated as any other character", - "expression": "'\\z'", - "result": "\\z" - }, - { - "comment": "Backslash not followed by single quote is treated as any other character", - "expression": "'\\\\'", - "result": "\\\\" + "cases": [ + { + "expression": "`\"foo\"`", + "result": "foo" + }, + { + "comment": "Interpret escaped unicode.", + "expression": "`\"\\u03a6\"`", + "result": "Φ" + }, + { + "expression": "`\"✓\"`", + "result": "✓" + }, + { + "expression": "`[1, 2, 3]`", + "result": [ + 1, + 2, + 3 + ] + }, + { + "expression": "`{\"a\": \"b\"}`", + "result": { + "a": "b" + } + }, + { + "expression": "`true`", + "result": true + }, + { + "expression": "`false`", + "result": false + }, + { + "expression": "`null`", + "result": null + }, + { + "expression": "`0`", + "result": 0 + }, + { + "expression": "`1`", + "result": 1 + }, + { + "expression": "`2`", + "result": 2 + }, + { + "expression": "`3`", + "result": 3 + }, + { + "expression": "`4`", + "result": 4 + }, + { + "expression": "`5`", + "result": 5 + }, + { + "expression": "`6`", + "result": 6 + }, + { + "expression": "`7`", + "result": 7 + }, + { + "expression": "`8`", + "result": 8 + }, + { + "expression": "`9`", + "result": 9 + }, + { + "comment": "Escaping a backtick in quotes", + "expression": "`\"foo\\`bar\"`", + "result": "foo`bar" + }, + { + "comment": "Double quote in literal", + "expression": "`\"foo\\\"bar\"`", + "result": "foo\"bar" + }, + { + "expression": "`\"1\\`\"`", + "result": "1`" + }, + { + "comment": "Multiple literal expressions with escapes", + "expression": "`\"\\\\\"`.{a:`\"b\"`}", + "result": { + "a": "b" + } + }, + { + "comment": "literal . identifier", + "expression": "`{\"a\": \"b\"}`.a", + "result": "b" + }, + { + "comment": "literal . identifier . identifier", + "expression": "`{\"a\": {\"b\": \"c\"}}`.a.b", + "result": "c" + }, + { + "comment": "literal . identifier bracket-expr", + "expression": "`[0, 1, 2]`[1]", + "result": 1 + } + ] + }, + { + "comment": "Literals", + "given": { + "type": "object" + }, + "cases": [ + { + "comment": "Literal with leading whitespace", + "expression": "` {\"foo\": true}`", + "result": { + "foo": true + } + }, + { + "comment": "Literal with trailing whitespace", + "expression": "`{\"foo\": true} `", + "result": { + "foo": true + } + }, + { + "comment": "Literal on RHS of subexpr not allowed", + "expression": "foo.`\"bar\"`", + "error": "syntax" + }, + { + "comment": "Literal with all valid leading and trailing JSON whitespace", + "expression": "` \t\n\r{\"foo\": true} \t\n\r`", + "result": { + "foo": true } - ] - } -] + }, + { + "comment": "Literal with non-JSON C0 control character U+000C FORM FEED", + "expression": "`0\f`", + "error": "syntax" + } + ] + }, + { + "comment": "Raw String Literals", + "given": {}, + "cases": [ + { + "expression": "'foo'", + "result": "foo" + }, + { + "expression": "' foo '", + "result": " foo " + }, + { + "expression": "'0'", + "result": "0" + }, + { + "expression": "'newline\n'", + "result": "newline\n" + }, + { + "expression": "'\n'", + "result": "\n" + }, + { + "expression": "'✓'", + "result": "✓" + }, + { + "expression": "'𝄞'", + "result": "𝄞" + }, + { + "expression": "' [foo] '", + "result": " [foo] " + }, + { + "expression": "'[foo]'", + "result": "[foo]" + }, + { + "comment": "Do not interpret escaped unicode.", + "expression": "'\\u03a6'", + "result": "\\u03a6" + }, + { + "comment": "Can escape the single quote", + "expression": "'foo\\'bar'", + "result": "foo'bar" + }, + { + "comment": "Backslash not followed by single quote is treated as any other character", + "expression": "'\\z'", + "result": "\\z" + }, + { + "comment": "Backslash not followed by single quote is treated as any other character", + "expression": "'\\\\'", + "result": "\\\\" + } + ] + } +] \ No newline at end of file