aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/json-tests.el
diff options
context:
space:
mode:
authorPhilipp Stephani2017-12-19 00:07:45 +0100
committerPhilipp Stephani2017-12-19 00:10:24 +0100
commit994ce51b28384bb2ea7a88248a105fcdc7c53a7b (patch)
treee25f0ec86fcb30b2b0ffb827f4aa04446de785eb /test/src/json-tests.el
parent9685774e38dc6f5670c8e57dc9f49335f4f738b6 (diff)
downloademacs-994ce51b28384bb2ea7a88248a105fcdc7c53a7b.tar.gz
emacs-994ce51b28384bb2ea7a88248a105fcdc7c53a7b.zip
JSON: Add tests for Unicode edge cases
* test/src/json-tests.el (json-serialize/string): Add test for serializing the null character. (json-parse-string/null): Add test for parsing the null character. (json-serialize/invalid-unicode): Add tests for invalid Unicode strings. (json-serialize/roundtrip): Add Unicode noncharacter, non-BMP characters, and syntactic characters.
Diffstat (limited to 'test/src/json-tests.el')
-rw-r--r--test/src/json-tests.el23
1 files changed, 20 insertions, 3 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 07eb41d0930..551f8ac5fe4 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -28,8 +28,10 @@
28 28
29(ert-deftest json-serialize/roundtrip () 29(ert-deftest json-serialize/roundtrip ()
30 (skip-unless (fboundp 'json-serialize)) 30 (skip-unless (fboundp 'json-serialize))
31 (let ((lisp [:null :false t 0 123 -456 3.75 "abcαβγ"]) 31 ;; The noncharacter U+FFFF should be passed through,
32 (json "[null,false,true,0,123,-456,3.75,\"abcαβγ\"]")) 32 ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters.
33 (let ((lisp [:null :false t 0 123 -456 3.75 "abc\uFFFFαβγ𝔸𝐁𝖢\"\\"])
34 (json "[null,false,true,0,123,-456,3.75,\"abc\uFFFFαβγ𝔸𝐁𝖢\\\"\\\\\"]"))
33 (should (equal (json-serialize lisp) json)) 35 (should (equal (json-serialize lisp) json))
34 (with-temp-buffer 36 (with-temp-buffer
35 (json-insert lisp) 37 (json-insert lisp)
@@ -75,7 +77,22 @@
75 (should (equal (json-serialize ["foo"]) "[\"foo\"]")) 77 (should (equal (json-serialize ["foo"]) "[\"foo\"]"))
76 (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]")) 78 (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]"))
77 (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"]) 79 (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"])
78 "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"))) 80 "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"))
81 (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]")))
82
83(ert-deftest json-serialize/invalid-unicode ()
84 (skip-unless (fboundp 'json-serialize))
85 ;; FIXME: "out of memory" is the wrong error signal, but we don't
86 ;; currently distinguish between error types when serializing.
87 (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory)
88 (should-error (json-serialize (vector (string ?a #x110000 ?b)))
89 :type 'json-out-of-memory)
90 (should-error (json-serialize ["a\xCCb"] :type 'json-out-of-memory)))
91
92(ert-deftest json-parse-string/null ()
93 (skip-unless (fboundp 'json-parse-string))
94 ;; FIXME: Reconsider whether this is the right behavior.
95 (should-error (json-parse-string "[a\\u0000b]") :type 'json-parse-error))
79 96
80(ert-deftest json-parse-string/incomplete () 97(ert-deftest json-parse-string/incomplete ()
81 (skip-unless (fboundp 'json-parse-string)) 98 (skip-unless (fboundp 'json-parse-string))