diff options
| author | Philipp Stephani | 2017-12-22 02:35:16 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2017-12-22 02:35:16 +0100 |
| commit | 9ced53ae8b381afbdd465081c7f82ebfd03be47b (patch) | |
| tree | b0bd5ee44e4b88c9664b2b385561a71d2222bd47 /test/src/json-tests.el | |
| parent | c99f0312129a189768d7139ecef93ddbdfa3622b (diff) | |
| download | emacs-9ced53ae8b381afbdd465081c7f82ebfd03be47b.tar.gz emacs-9ced53ae8b381afbdd465081c7f82ebfd03be47b.zip | |
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.el | 22 |
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 @@ | |||
| 88 | ;; currently distinguish between error types when serializing. | 88 | ;; currently distinguish between error types when serializing. |
| 89 | (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) | 89 | (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) |
| 90 | (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) | 90 | (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) |
| 91 | (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory) | ||
| 91 | (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)) | 92 | (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)) |
| 92 | 93 | ||
| 93 | (ert-deftest json-parse-string/null () | 94 | (ert-deftest json-parse-string/null () |
| 94 | (skip-unless (fboundp 'json-parse-string)) | 95 | (skip-unless (fboundp 'json-parse-string)) |
| 96 | (should-error (json-parse-string "\x00") :type 'wrong-type-argument) | ||
| 95 | ;; FIXME: Reconsider whether this is the right behavior. | 97 | ;; FIXME: Reconsider whether this is the right behavior. |
| 96 | (should-error (json-parse-string "[a\\u0000b]") :type 'json-parse-error)) | 98 | (should-error (json-parse-string "[a\\u0000b]") :type 'json-parse-error)) |
| 97 | 99 | ||
| 100 | (ert-deftest json-parse-string/invalid-unicode () | ||
| 101 | "Some examples from | ||
| 102 | https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt." | ||
| 103 | (skip-unless (fboundp 'json-parse-string)) | ||
| 104 | ;; Invalid UTF-8 code unit sequences. | ||
| 105 | (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) | ||
| 106 | (should-error (json-parse-string "[\"\xBF\"]") :type 'json-parse-error) | ||
| 107 | (should-error (json-parse-string "[\"\xFE\"]") :type 'json-parse-error) | ||
| 108 | (should-error (json-parse-string "[\"\xC0\xAF\"]") :type 'json-parse-error) | ||
| 109 | (should-error (json-parse-string "[\"\xC0\x80\"]") :type 'json-parse-error) | ||
| 110 | ;; Surrogates. | ||
| 111 | (should-error (json-parse-string "[\"\uDB7F\"]") | ||
| 112 | :type 'json-parse-error) | ||
| 113 | (should-error (json-parse-string "[\"\xED\xAD\xBF\"]") | ||
| 114 | :type 'json-parse-error) | ||
| 115 | (should-error (json-parse-string "[\"\uDB7F\uDFFF\"]") | ||
| 116 | :type 'json-parse-error) | ||
| 117 | (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]") | ||
| 118 | :type 'json-parse-error)) | ||
| 119 | |||
| 98 | (ert-deftest json-parse-string/incomplete () | 120 | (ert-deftest json-parse-string/incomplete () |
| 99 | (skip-unless (fboundp 'json-parse-string)) | 121 | (skip-unless (fboundp 'json-parse-string)) |
| 100 | (should-error (json-parse-string "[123") :type 'json-end-of-file)) | 122 | (should-error (json-parse-string "[123") :type 'json-end-of-file)) |