summaryrefslogtreecommitdiff
path: root/test/src/json-tests.el
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2017-12-22 02:35:16 +0100
committerPhilipp Stephani <phst@google.com>2017-12-22 02:35:16 +0100
commit9ced53ae8b381afbdd465081c7f82ebfd03be47b (patch)
treeb0bd5ee44e4b88c9664b2b385561a71d2222bd47 /test/src/json-tests.el
parentc99f0312129a189768d7139ecef93ddbdfa3622b (diff)
downloademacs-9ced53ae8b381afbdd465081c7f82ebfd03be47b.tar.gz
Add a few more unit tests for JSON
* test/src/json-tests.el (json-serialize/invalid-unicode) (json-parse-string/null): Add more tests. (json-parse-string/invalid-unicode): New test.
Diffstat (limited to 'test/src/json-tests.el')
-rw-r--r--test/src/json-tests.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 71aa4a8b783..9884e9a2d57 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -88,13 +88,35 @@
;; currently distinguish between error types when serializing.
(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))
(ert-deftest json-parse-string/null ()
(skip-unless (fboundp 'json-parse-string))
+ (should-error (json-parse-string "\x00") :type 'wrong-type-argument)
;; FIXME: Reconsider whether this is the right behavior.
(should-error (json-parse-string "[a\\u0000b]") :type 'json-parse-error))
+(ert-deftest json-parse-string/invalid-unicode ()
+ "Some examples from
+https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt."
+ (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 "[\"\xBF\"]") :type 'json-parse-error)
+ (should-error (json-parse-string "[\"\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)
+ ;; 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 "[\"\uDB7F\uDFFF\"]")
+ :type 'json-parse-error)
+ (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]")
+ :type 'json-parse-error))
+
(ert-deftest json-parse-string/incomplete ()
(skip-unless (fboundp 'json-parse-string))
(should-error (json-parse-string "[123") :type 'json-end-of-file))