diff options
| author | Mattias Engdegård | 2024-03-31 15:07:34 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2024-04-01 09:42:46 +0200 |
| commit | f178a6d8006f1e8afe06bb71d0a413622d73f131 (patch) | |
| tree | d8b0772c384b7cec70582e5aa539456b073523ee /test/src/json-tests.el | |
| parent | 155462a1bd7909074f79a534324c7b209eb97142 (diff) | |
| download | emacs-f178a6d8006f1e8afe06bb71d0a413622d73f131.tar.gz emacs-f178a6d8006f1e8afe06bb71d0a413622d73f131.zip | |
Native JSON support is always available
* lisp/progmodes/sh-script.el (sh--json-read): Remove.
(sh-shellcheck-flymake): Call json-parse-buffer directly.
* test/src/json-tests.el: Don't check for function availability.
Diffstat (limited to '')
| -rw-r--r-- | test/src/json-tests.el | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index e5cbe8bff5c..fb2384d4a8d 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -34,7 +34,6 @@ | |||
| 34 | (define-error 'json-tests--error "JSON test error") | 34 | (define-error 'json-tests--error "JSON test error") |
| 35 | 35 | ||
| 36 | (ert-deftest json-serialize/roundtrip () | 36 | (ert-deftest json-serialize/roundtrip () |
| 37 | (skip-unless (fboundp 'json-serialize)) | ||
| 38 | ;; The noncharacter U+FFFF should be passed through, | 37 | ;; The noncharacter U+FFFF should be passed through, |
| 39 | ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters. | 38 | ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters. |
| 40 | (let ((lisp [:null :false t 0 123 -456 3.75 "abc\uFFFFαβγ𝔸𝐁𝖢\"\\"]) | 39 | (let ((lisp [:null :false t 0 123 -456 3.75 "abc\uFFFFαβγ𝔸𝐁𝖢\"\\"]) |
| @@ -53,7 +52,6 @@ | |||
| 53 | 52 | ||
| 54 | (ert-deftest json-serialize/roundtrip-scalars () | 53 | (ert-deftest json-serialize/roundtrip-scalars () |
| 55 | "Check that Bug#42994 is fixed." | 54 | "Check that Bug#42994 is fixed." |
| 56 | (skip-unless (fboundp 'json-serialize)) | ||
| 57 | (dolist (case '((:null "null") | 55 | (dolist (case '((:null "null") |
| 58 | (:false "false") | 56 | (:false "false") |
| 59 | (t "true") | 57 | (t "true") |
| @@ -80,7 +78,6 @@ | |||
| 80 | (should (eobp))))))) | 78 | (should (eobp))))))) |
| 81 | 79 | ||
| 82 | (ert-deftest json-serialize/object () | 80 | (ert-deftest json-serialize/object () |
| 83 | (skip-unless (fboundp 'json-serialize)) | ||
| 84 | (let ((table (make-hash-table :test #'equal))) | 81 | (let ((table (make-hash-table :test #'equal))) |
| 85 | (puthash "abc" [1 2 t] table) | 82 | (puthash "abc" [1 2 t] table) |
| 86 | (puthash "def" :null table) | 83 | (puthash "def" :null table) |
| @@ -125,8 +122,6 @@ | |||
| 125 | }"))) | 122 | }"))) |
| 126 | 123 | ||
| 127 | (ert-deftest json-serialize/object-with-duplicate-keys () | 124 | (ert-deftest json-serialize/object-with-duplicate-keys () |
| 128 | (skip-unless (fboundp 'json-serialize)) | ||
| 129 | |||
| 130 | (dolist (n '(1 5 20 100)) | 125 | (dolist (n '(1 5 20 100)) |
| 131 | (let ((symbols (mapcar (lambda (i) (make-symbol (format "s%d" i))) | 126 | (let ((symbols (mapcar (lambda (i) (make-symbol (format "s%d" i))) |
| 132 | (number-sequence 1 n))) | 127 | (number-sequence 1 n))) |
| @@ -160,7 +155,6 @@ | |||
| 160 | ) | 155 | ) |
| 161 | 156 | ||
| 162 | (ert-deftest json-parse-string/object () | 157 | (ert-deftest json-parse-string/object () |
| 163 | (skip-unless (fboundp 'json-parse-string)) | ||
| 164 | (let ((input | 158 | (let ((input |
| 165 | "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n")) | 159 | "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n")) |
| 166 | (let ((actual (json-parse-string input))) | 160 | (let ((actual (json-parse-string input))) |
| @@ -174,7 +168,6 @@ | |||
| 174 | '(:abc [9 :false] :def :null))))) | 168 | '(:abc [9 :false] :def :null))))) |
| 175 | 169 | ||
| 176 | (ert-deftest json-parse-string/array () | 170 | (ert-deftest json-parse-string/array () |
| 177 | (skip-unless (fboundp 'json-parse-string)) | ||
| 178 | (let ((input "[\"a\", 1, [\"b\", 2]]")) | 171 | (let ((input "[\"a\", 1, [\"b\", 2]]")) |
| 179 | (should (equal (json-parse-string input) | 172 | (should (equal (json-parse-string input) |
| 180 | ["a" 1 ["b" 2]])) | 173 | ["a" 1 ["b" 2]])) |
| @@ -182,7 +175,6 @@ | |||
| 182 | '("a" 1 ("b" 2)))))) | 175 | '("a" 1 ("b" 2)))))) |
| 183 | 176 | ||
| 184 | (ert-deftest json-parse-string/string () | 177 | (ert-deftest json-parse-string/string () |
| 185 | (skip-unless (fboundp 'json-parse-string)) | ||
| 186 | (should-error (json-parse-string "[\"formfeed\f\"]") :type 'json-parse-error) | 178 | (should-error (json-parse-string "[\"formfeed\f\"]") :type 'json-parse-error) |
| 187 | (should (equal (json-parse-string "[\"foo \\\"bar\\\"\"]") ["foo \"bar\""])) | 179 | (should (equal (json-parse-string "[\"foo \\\"bar\\\"\"]") ["foo \"bar\""])) |
| 188 | (should (equal (json-parse-string "[\"abcαβγ\"]") ["abcαβγ"])) | 180 | (should (equal (json-parse-string "[\"abcαβγ\"]") ["abcαβγ"])) |
| @@ -194,7 +186,6 @@ | |||
| 194 | (should (equal (json-parse-string "[\"\u00C4\xC3\x84\"]") ["\u00C4\u00C4"]))) | 186 | (should (equal (json-parse-string "[\"\u00C4\xC3\x84\"]") ["\u00C4\u00C4"]))) |
| 195 | 187 | ||
| 196 | (ert-deftest json-serialize/string () | 188 | (ert-deftest json-serialize/string () |
| 197 | (skip-unless (fboundp 'json-serialize)) | ||
| 198 | (should (equal (json-serialize ["foo"]) "[\"foo\"]")) | 189 | (should (equal (json-serialize ["foo"]) "[\"foo\"]")) |
| 199 | (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]")) | 190 | (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]")) |
| 200 | (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"]) | 191 | (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"]) |
| @@ -204,7 +195,6 @@ | |||
| 204 | (should-error (json-serialize ["\u00C4\xC3\x84"]))) | 195 | (should-error (json-serialize ["\u00C4\xC3\x84"]))) |
| 205 | 196 | ||
| 206 | (ert-deftest json-serialize/invalid-unicode () | 197 | (ert-deftest json-serialize/invalid-unicode () |
| 207 | (skip-unless (fboundp 'json-serialize)) | ||
| 208 | (should-error (json-serialize ["a\uDBBBb"]) :type 'wrong-type-argument) | 198 | (should-error (json-serialize ["a\uDBBBb"]) :type 'wrong-type-argument) |
| 209 | (should-error (json-serialize ["u\x110000v"]) :type 'wrong-type-argument) | 199 | (should-error (json-serialize ["u\x110000v"]) :type 'wrong-type-argument) |
| 210 | (should-error (json-serialize ["u\x3FFFFFv"]) :type 'wrong-type-argument) | 200 | (should-error (json-serialize ["u\x3FFFFFv"]) :type 'wrong-type-argument) |
| @@ -212,7 +202,6 @@ | |||
| 212 | (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'wrong-type-argument)) | 202 | (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'wrong-type-argument)) |
| 213 | 203 | ||
| 214 | (ert-deftest json-parse-string/null () | 204 | (ert-deftest json-parse-string/null () |
| 215 | (skip-unless (fboundp 'json-parse-string)) | ||
| 216 | (should-error (json-parse-string "\x00") :type 'wrong-type-argument) | 205 | (should-error (json-parse-string "\x00") :type 'wrong-type-argument) |
| 217 | (should (json-parse-string "[\"a\\u0000b\"]")) | 206 | (should (json-parse-string "[\"a\\u0000b\"]")) |
| 218 | (let* ((string "{\"foo\":\"this is a string including a literal \\u0000\"}") | 207 | (let* ((string "{\"foo\":\"this is a string including a literal \\u0000\"}") |
| @@ -224,7 +213,6 @@ | |||
| 224 | "Some examples from | 213 | "Some examples from |
| 225 | https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt. | 214 | https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt. |
| 226 | Test with both unibyte and multibyte strings." | 215 | Test with both unibyte and multibyte strings." |
| 227 | (skip-unless (fboundp 'json-parse-string)) | ||
| 228 | ;; Invalid UTF-8 code unit sequences. | 216 | ;; Invalid UTF-8 code unit sequences. |
| 229 | (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) | 217 | (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) |
| 230 | (should-error (json-parse-string "[\"\u00C4\x80\"]") :type 'json-parse-error) | 218 | (should-error (json-parse-string "[\"\u00C4\x80\"]") :type 'json-parse-error) |
| @@ -252,15 +240,12 @@ Test with both unibyte and multibyte strings." | |||
| 252 | :type 'json-parse-error)) | 240 | :type 'json-parse-error)) |
| 253 | 241 | ||
| 254 | (ert-deftest json-parse-string/incomplete () | 242 | (ert-deftest json-parse-string/incomplete () |
| 255 | (skip-unless (fboundp 'json-parse-string)) | ||
| 256 | (should-error (json-parse-string "[123") :type 'json-end-of-file)) | 243 | (should-error (json-parse-string "[123") :type 'json-end-of-file)) |
| 257 | 244 | ||
| 258 | (ert-deftest json-parse-string/trailing () | 245 | (ert-deftest json-parse-string/trailing () |
| 259 | (skip-unless (fboundp 'json-parse-string)) | ||
| 260 | (should-error (json-parse-string "[123] [456]") :type 'json-trailing-content)) | 246 | (should-error (json-parse-string "[123] [456]") :type 'json-trailing-content)) |
| 261 | 247 | ||
| 262 | (ert-deftest json-parse-buffer/incomplete () | 248 | (ert-deftest json-parse-buffer/incomplete () |
| 263 | (skip-unless (fboundp 'json-parse-buffer)) | ||
| 264 | (with-temp-buffer | 249 | (with-temp-buffer |
| 265 | (insert "[123") | 250 | (insert "[123") |
| 266 | (goto-char 1) | 251 | (goto-char 1) |
| @@ -268,7 +253,6 @@ Test with both unibyte and multibyte strings." | |||
| 268 | (should (bobp)))) | 253 | (should (bobp)))) |
| 269 | 254 | ||
| 270 | (ert-deftest json-parse-buffer/trailing () | 255 | (ert-deftest json-parse-buffer/trailing () |
| 271 | (skip-unless (fboundp 'json-parse-buffer)) | ||
| 272 | (with-temp-buffer | 256 | (with-temp-buffer |
| 273 | (insert "[123] [456]") | 257 | (insert "[123] [456]") |
| 274 | (goto-char 1) | 258 | (goto-char 1) |
| @@ -277,8 +261,6 @@ Test with both unibyte and multibyte strings." | |||
| 277 | (should (looking-at-p (rx " [456]" eos))))) | 261 | (should (looking-at-p (rx " [456]" eos))))) |
| 278 | 262 | ||
| 279 | (ert-deftest json-parse-with-custom-null-and-false-objects () | 263 | (ert-deftest json-parse-with-custom-null-and-false-objects () |
| 280 | (skip-unless (and (fboundp 'json-serialize) | ||
| 281 | (fboundp 'json-parse-string))) | ||
| 282 | (let* ((input | 264 | (let* ((input |
| 283 | "{ \"abc\" : [9, false] , \"def\" : null }") | 265 | "{ \"abc\" : [9, false] , \"def\" : null }") |
| 284 | (output | 266 | (output |
| @@ -316,7 +298,6 @@ Test with both unibyte and multibyte strings." | |||
| 316 | (should-error (json-serialize '() :object-type 'alist)))) | 298 | (should-error (json-serialize '() :object-type 'alist)))) |
| 317 | 299 | ||
| 318 | (ert-deftest json-insert/signal () | 300 | (ert-deftest json-insert/signal () |
| 319 | (skip-unless (fboundp 'json-insert)) | ||
| 320 | (with-temp-buffer | 301 | (with-temp-buffer |
| 321 | (let ((calls 0)) | 302 | (let ((calls 0)) |
| 322 | (add-hook 'after-change-functions | 303 | (add-hook 'after-change-functions |
| @@ -331,7 +312,6 @@ Test with both unibyte and multibyte strings." | |||
| 331 | (should (equal calls 1))))) | 312 | (should (equal calls 1))))) |
| 332 | 313 | ||
| 333 | (ert-deftest json-insert/throw () | 314 | (ert-deftest json-insert/throw () |
| 334 | (skip-unless (fboundp 'json-insert)) | ||
| 335 | (with-temp-buffer | 315 | (with-temp-buffer |
| 336 | (let ((calls 0)) | 316 | (let ((calls 0)) |
| 337 | (add-hook 'after-change-functions | 317 | (add-hook 'after-change-functions |
| @@ -347,7 +327,6 @@ Test with both unibyte and multibyte strings." | |||
| 347 | (should (equal calls 1))))) | 327 | (should (equal calls 1))))) |
| 348 | 328 | ||
| 349 | (ert-deftest json-serialize/bignum () | 329 | (ert-deftest json-serialize/bignum () |
| 350 | (skip-unless (fboundp 'json-serialize)) | ||
| 351 | (should (equal (json-serialize (vector (1+ most-positive-fixnum) | 330 | (should (equal (json-serialize (vector (1+ most-positive-fixnum) |
| 352 | (1- most-negative-fixnum))) | 331 | (1- most-negative-fixnum))) |
| 353 | (format "[%d,%d]" | 332 | (format "[%d,%d]" |
| @@ -356,12 +335,10 @@ Test with both unibyte and multibyte strings." | |||
| 356 | 335 | ||
| 357 | (ert-deftest json-parse-string/wrong-type () | 336 | (ert-deftest json-parse-string/wrong-type () |
| 358 | "Check that Bug#42113 is fixed." | 337 | "Check that Bug#42113 is fixed." |
| 359 | (skip-unless (fboundp 'json-parse-string)) | ||
| 360 | (should-error (json-parse-string 1) :type 'wrong-type-argument)) | 338 | (should-error (json-parse-string 1) :type 'wrong-type-argument)) |
| 361 | 339 | ||
| 362 | (ert-deftest json-serialize/wrong-hash-key-type () | 340 | (ert-deftest json-serialize/wrong-hash-key-type () |
| 363 | "Check that Bug#42113 is fixed." | 341 | "Check that Bug#42113 is fixed." |
| 364 | (skip-unless (fboundp 'json-serialize)) | ||
| 365 | (let ((table (make-hash-table :test #'eq))) | 342 | (let ((table (make-hash-table :test #'eq))) |
| 366 | (puthash 1 2 table) | 343 | (puthash 1 2 table) |
| 367 | (should-error (json-serialize table) :type 'wrong-type-argument))) | 344 | (should-error (json-serialize table) :type 'wrong-type-argument))) |