aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/json-tests.el
diff options
context:
space:
mode:
authorPhilipp Stephani2017-12-24 14:12:19 +0100
committerPhilipp Stephani2017-12-24 14:12:19 +0100
commit3f63ae54ecc22de51930cba1b118e93f7decd45e (patch)
tree487ddaa8bc2f89bff9cdc032ac64780c5fa61ede /test/src/json-tests.el
parentf552a957ada23a7ff182fc1ab94221ced3ed1713 (diff)
downloademacs-3f63ae54ecc22de51930cba1b118e93f7decd45e.tar.gz
emacs-3f63ae54ecc22de51930cba1b118e93f7decd45e.zip
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.
Diffstat (limited to '')
-rw-r--r--test/src/json-tests.el26
1 files changed, 21 insertions, 5 deletions
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 @@
92 (should (equal (json-parse-string "[\"\\nasd\\u0444\\u044b\\u0432fgh\\t\"]") 92 (should (equal (json-parse-string "[\"\\nasd\\u0444\\u044b\\u0432fgh\\t\"]")
93 ["\nasdфывfgh\t"])) 93 ["\nasdфывfgh\t"]))
94 (should (equal (json-parse-string "[\"\\uD834\\uDD1E\"]") ["\U0001D11E"])) 94 (should (equal (json-parse-string "[\"\\uD834\\uDD1E\"]") ["\U0001D11E"]))
95 (should-error (json-parse-string "foo") :type 'json-parse-error)) 95 (should-error (json-parse-string "foo") :type 'json-parse-error)
96 ;; FIXME: Is this the right behavior?
97 (should (equal (json-parse-string "[\"\u00C4\xC3\x84\"]") ["\u00C4\u00C4"])))
96 98
97(ert-deftest json-serialize/string () 99(ert-deftest json-serialize/string ()
98 (skip-unless (fboundp 'json-serialize)) 100 (skip-unless (fboundp 'json-serialize))
@@ -100,7 +102,9 @@
100 (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]")) 102 (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]"))
101 (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"]) 103 (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"])
102 "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]")) 104 "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"))
103 (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]"))) 105 (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]"))
106 ;; FIXME: Is this the right behavior?
107 (should (equal (json-serialize ["\u00C4\xC3\x84"]) "[\"\u00C4\u00C4\"]")))
104 108
105(ert-deftest json-serialize/invalid-unicode () 109(ert-deftest json-serialize/invalid-unicode ()
106 (skip-unless (fboundp 'json-serialize)) 110 (skip-unless (fboundp 'json-serialize))
@@ -109,7 +113,8 @@
109 (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) 113 (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory)
110 (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) 114 (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory)
111 (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory) 115 (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory)
112 (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)) 116 (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)
117 (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'json-out-of-memory))
113 118
114(ert-deftest json-parse-string/null () 119(ert-deftest json-parse-string/null ()
115 (skip-unless (fboundp 'json-parse-string)) 120 (skip-unless (fboundp 'json-parse-string))
@@ -119,22 +124,33 @@
119 124
120(ert-deftest json-parse-string/invalid-unicode () 125(ert-deftest json-parse-string/invalid-unicode ()
121 "Some examples from 126 "Some examples from
122https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt." 127https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt.
128Test with both unibyte and multibyte strings."
123 (skip-unless (fboundp 'json-parse-string)) 129 (skip-unless (fboundp 'json-parse-string))
124 ;; Invalid UTF-8 code unit sequences. 130 ;; Invalid UTF-8 code unit sequences.
125 (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) 131 (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error)
132 (should-error (json-parse-string "[\"\u00C4\x80\"]") :type 'json-parse-error)
126 (should-error (json-parse-string "[\"\xBF\"]") :type 'json-parse-error) 133 (should-error (json-parse-string "[\"\xBF\"]") :type 'json-parse-error)
134 (should-error (json-parse-string "[\"\u00C4\xBF\"]") :type 'json-parse-error)
127 (should-error (json-parse-string "[\"\xFE\"]") :type 'json-parse-error) 135 (should-error (json-parse-string "[\"\xFE\"]") :type 'json-parse-error)
136 (should-error (json-parse-string "[\"\u00C4\xFE\"]") :type 'json-parse-error)
128 (should-error (json-parse-string "[\"\xC0\xAF\"]") :type 'json-parse-error) 137 (should-error (json-parse-string "[\"\xC0\xAF\"]") :type 'json-parse-error)
129 (should-error (json-parse-string "[\"\xC0\x80\"]") :type 'json-parse-error) 138 (should-error (json-parse-string "[\"\u00C4\xC0\xAF\"]")
139 :type 'json-parse-error)
140 (should-error (json-parse-string "[\"\u00C4\xC0\x80\"]")
141 :type 'json-parse-error)
130 ;; Surrogates. 142 ;; Surrogates.
131 (should-error (json-parse-string "[\"\uDB7F\"]") 143 (should-error (json-parse-string "[\"\uDB7F\"]")
132 :type 'json-parse-error) 144 :type 'json-parse-error)
133 (should-error (json-parse-string "[\"\xED\xAD\xBF\"]") 145 (should-error (json-parse-string "[\"\xED\xAD\xBF\"]")
134 :type 'json-parse-error) 146 :type 'json-parse-error)
147 (should-error (json-parse-string "[\"\u00C4\xED\xAD\xBF\"]")
148 :type 'json-parse-error)
135 (should-error (json-parse-string "[\"\uDB7F\uDFFF\"]") 149 (should-error (json-parse-string "[\"\uDB7F\uDFFF\"]")
136 :type 'json-parse-error) 150 :type 'json-parse-error)
137 (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]") 151 (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]")
152 :type 'json-parse-error)
153 (should-error (json-parse-string "[\"\u00C4\xED\xAD\xBF\xED\xBF\xBF\"]")
138 :type 'json-parse-error)) 154 :type 'json-parse-error))
139 155
140(ert-deftest json-parse-string/incomplete () 156(ert-deftest json-parse-string/incomplete ()