emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 9ced53a: Add a few more unit tests for JSON


From: Philipp Stephani
Subject: [Emacs-diffs] master 9ced53a: Add a few more unit tests for JSON
Date: Thu, 21 Dec 2017 20:35:57 -0500 (EST)

branch: master
commit 9ced53ae8b381afbdd465081c7f82ebfd03be47b
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    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.
---
 test/src/json-tests.el | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 71aa4a8..9884e9a 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]