From: Philipp Stephani Date: Sun, 24 Dec 2017 13:12:19 +0000 (+0100) Subject: Add more Unicode test cases for JSON conversion X-Git-Tag: emacs-27.0.90~5967 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3f63ae54ecc22de51930cba1b118e93f7decd45e;p=emacs.git Add more Unicode test cases for JSON conversion * test/src/json-tests.el (json-parse-string/string) (json-serialize/string, json-serialize/invalid-unicode) (json-parse-string/invalid-unicode): Add more Unicode test cases. --- diff --git a/test/src/json-tests.el b/test/src/json-tests.el index b23439a59fd..e394583bc76 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el @@ -92,7 +92,9 @@ (should (equal (json-parse-string "[\"\\nasd\\u0444\\u044b\\u0432fgh\\t\"]") ["\nasdфывfgh\t"])) (should (equal (json-parse-string "[\"\\uD834\\uDD1E\"]") ["\U0001D11E"])) - (should-error (json-parse-string "foo") :type 'json-parse-error)) + (should-error (json-parse-string "foo") :type 'json-parse-error) + ;; FIXME: Is this the right behavior? + (should (equal (json-parse-string "[\"\u00C4\xC3\x84\"]") ["\u00C4\u00C4"]))) (ert-deftest json-serialize/string () (skip-unless (fboundp 'json-serialize)) @@ -100,7 +102,9 @@ (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]")) (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"]) "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]")) - (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]"))) + (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]")) + ;; FIXME: Is this the right behavior? + (should (equal (json-serialize ["\u00C4\xC3\x84"]) "[\"\u00C4\u00C4\"]"))) (ert-deftest json-serialize/invalid-unicode () (skip-unless (fboundp 'json-serialize)) @@ -109,7 +113,8 @@ (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory) - (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)) + (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory) + (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'json-out-of-memory)) (ert-deftest json-parse-string/null () (skip-unless (fboundp 'json-parse-string)) @@ -119,22 +124,33 @@ (ert-deftest json-parse-string/invalid-unicode () "Some examples from -https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt." +https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt. +Test with both unibyte and multibyte strings." (skip-unless (fboundp 'json-parse-string)) ;; Invalid UTF-8 code unit sequences. (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\x80\"]") :type 'json-parse-error) (should-error (json-parse-string "[\"\xBF\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xBF\"]") :type 'json-parse-error) (should-error (json-parse-string "[\"\xFE\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xFE\"]") :type 'json-parse-error) (should-error (json-parse-string "[\"\xC0\xAF\"]") :type 'json-parse-error) - (should-error (json-parse-string "[\"\xC0\x80\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xC0\xAF\"]") + :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xC0\x80\"]") + :type 'json-parse-error) ;; Surrogates. (should-error (json-parse-string "[\"\uDB7F\"]") :type 'json-parse-error) (should-error (json-parse-string "[\"\xED\xAD\xBF\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xED\xAD\xBF\"]") + :type 'json-parse-error) (should-error (json-parse-string "[\"\uDB7F\uDFFF\"]") :type 'json-parse-error) (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]") + :type 'json-parse-error) + (should-error (json-parse-string "[\"\u00C4\xED\xAD\xBF\xED\xBF\xBF\"]") :type 'json-parse-error)) (ert-deftest json-parse-string/incomplete ()