emacs-diffs
[Top][All Lists]
Advanced

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

master f178a6d8006 2/4: Native JSON support is always available


From: Mattias Engdegård
Subject: master f178a6d8006 2/4: Native JSON support is always available
Date: Mon, 1 Apr 2024 04:45:04 -0400 (EDT)

branch: master
commit f178a6d8006f1e8afe06bb71d0a413622d73f131
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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.
---
 lisp/progmodes/sh-script.el |  8 +-------
 test/src/json-tests.el      | 23 -----------------------
 2 files changed, 1 insertion(+), 30 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index ab95dc9f924..20c9e00edbf 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -3194,12 +3194,6 @@ shell command and conveniently use this command."
 
 (defvar-local sh--shellcheck-process nil)
 
-(defalias 'sh--json-read
-  (if (fboundp 'json-parse-buffer)
-      (lambda () (json-parse-buffer :object-type 'alist))
-    (require 'json)
-    'json-read))
-
 (defun sh-shellcheck-flymake (report-fn &rest _args)
   "Flymake backend using the shellcheck program.
 Takes a Flymake callback REPORT-FN as argument, as expected of a
@@ -3223,7 +3217,7 @@ member of `flymake-diagnostic-functions'."
                     (with-current-buffer (process-buffer proc)
                       (goto-char (point-min))
                       (thread-last
-                        (sh--json-read)
+                        (json-parse-buffer :object-type 'alist)
                         (alist-get 'comments)
                         (seq-filter
                          (lambda (item)
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 @@
 (define-error 'json-tests--error "JSON test error")
 
 (ert-deftest json-serialize/roundtrip ()
-  (skip-unless (fboundp 'json-serialize))
   ;; The noncharacter U+FFFF should be passed through,
   ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters.
   (let ((lisp [:null :false t 0 123 -456 3.75 "abc\uFFFFαβγ𝔸𝐁𝖢\"\\"])
@@ -53,7 +52,6 @@
 
 (ert-deftest json-serialize/roundtrip-scalars ()
   "Check that Bug#42994 is fixed."
-  (skip-unless (fboundp 'json-serialize))
   (dolist (case '((:null "null")
                   (:false "false")
                   (t "true")
@@ -80,7 +78,6 @@
           (should (eobp)))))))
 
 (ert-deftest json-serialize/object ()
-  (skip-unless (fboundp 'json-serialize))
   (let ((table (make-hash-table :test #'equal)))
     (puthash "abc" [1 2 t] table)
     (puthash "def" :null table)
@@ -125,8 +122,6 @@
 }")))
 
 (ert-deftest json-serialize/object-with-duplicate-keys ()
-  (skip-unless (fboundp 'json-serialize))
-
   (dolist (n '(1 5 20 100))
     (let ((symbols (mapcar (lambda (i) (make-symbol (format "s%d" i)))
                            (number-sequence 1 n)))
@@ -160,7 +155,6 @@
   )
 
 (ert-deftest json-parse-string/object ()
-  (skip-unless (fboundp 'json-parse-string))
   (let ((input
          "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n"))
     (let ((actual (json-parse-string input)))
@@ -174,7 +168,6 @@
                    '(:abc [9 :false] :def :null)))))
 
 (ert-deftest json-parse-string/array ()
-  (skip-unless (fboundp 'json-parse-string))
   (let ((input "[\"a\", 1, [\"b\", 2]]"))
     (should (equal (json-parse-string input)
                    ["a" 1 ["b" 2]]))
@@ -182,7 +175,6 @@
                    '("a" 1 ("b" 2))))))
 
 (ert-deftest json-parse-string/string ()
-  (skip-unless (fboundp 'json-parse-string))
   (should-error (json-parse-string "[\"formfeed\f\"]") :type 'json-parse-error)
   (should (equal (json-parse-string "[\"foo \\\"bar\\\"\"]") ["foo \"bar\""]))
   (should (equal (json-parse-string "[\"abcαβγ\"]") ["abcαβγ"]))
@@ -194,7 +186,6 @@
   (should (equal (json-parse-string "[\"\u00C4\xC3\x84\"]") ["\u00C4\u00C4"])))
 
 (ert-deftest json-serialize/string ()
-  (skip-unless (fboundp 'json-serialize))
   (should (equal (json-serialize ["foo"]) "[\"foo\"]"))
   (should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]"))
   (should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"])
@@ -204,7 +195,6 @@
   (should-error (json-serialize ["\u00C4\xC3\x84"])))
 
 (ert-deftest json-serialize/invalid-unicode ()
-  (skip-unless (fboundp 'json-serialize))
   (should-error (json-serialize ["a\uDBBBb"]) :type 'wrong-type-argument)
   (should-error (json-serialize ["u\x110000v"]) :type 'wrong-type-argument)
   (should-error (json-serialize ["u\x3FFFFFv"]) :type 'wrong-type-argument)
@@ -212,7 +202,6 @@
   (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'wrong-type-argument))
 
 (ert-deftest json-parse-string/null ()
-  (skip-unless (fboundp 'json-parse-string))
   (should-error (json-parse-string "\x00") :type 'wrong-type-argument)
   (should (json-parse-string "[\"a\\u0000b\"]"))
   (let* ((string "{\"foo\":\"this is a string including a literal \\u0000\"}")
@@ -224,7 +213,6 @@
   "Some examples from
 https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt.
 Test with both unibyte and multibyte strings."
-  (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 "[\"\u00C4\x80\"]") :type 'json-parse-error)
@@ -252,15 +240,12 @@ Test with both unibyte and multibyte strings."
                 :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))
 
 (ert-deftest json-parse-string/trailing ()
-  (skip-unless (fboundp 'json-parse-string))
   (should-error (json-parse-string "[123] [456]") :type 
'json-trailing-content))
 
 (ert-deftest json-parse-buffer/incomplete ()
-  (skip-unless (fboundp 'json-parse-buffer))
   (with-temp-buffer
     (insert "[123")
     (goto-char 1)
@@ -268,7 +253,6 @@ Test with both unibyte and multibyte strings."
     (should (bobp))))
 
 (ert-deftest json-parse-buffer/trailing ()
-  (skip-unless (fboundp 'json-parse-buffer))
   (with-temp-buffer
     (insert "[123] [456]")
     (goto-char 1)
@@ -277,8 +261,6 @@ Test with both unibyte and multibyte strings."
     (should (looking-at-p (rx " [456]" eos)))))
 
 (ert-deftest json-parse-with-custom-null-and-false-objects ()
-  (skip-unless (and (fboundp 'json-serialize)
-                    (fboundp 'json-parse-string)))
   (let* ((input
           "{ \"abc\" : [9, false] , \"def\" : null }")
          (output
@@ -316,7 +298,6 @@ Test with both unibyte and multibyte strings."
     (should-error (json-serialize '() :object-type 'alist))))
 
 (ert-deftest json-insert/signal ()
-  (skip-unless (fboundp 'json-insert))
   (with-temp-buffer
     (let ((calls 0))
       (add-hook 'after-change-functions
@@ -331,7 +312,6 @@ Test with both unibyte and multibyte strings."
       (should (equal calls 1)))))
 
 (ert-deftest json-insert/throw ()
-  (skip-unless (fboundp 'json-insert))
   (with-temp-buffer
     (let ((calls 0))
       (add-hook 'after-change-functions
@@ -347,7 +327,6 @@ Test with both unibyte and multibyte strings."
       (should (equal calls 1)))))
 
 (ert-deftest json-serialize/bignum ()
-  (skip-unless (fboundp 'json-serialize))
   (should (equal (json-serialize (vector (1+ most-positive-fixnum)
                                          (1- most-negative-fixnum)))
                  (format "[%d,%d]"
@@ -356,12 +335,10 @@ Test with both unibyte and multibyte strings."
 
 (ert-deftest json-parse-string/wrong-type ()
   "Check that Bug#42113 is fixed."
-  (skip-unless (fboundp 'json-parse-string))
   (should-error (json-parse-string 1) :type 'wrong-type-argument))
 
 (ert-deftest json-serialize/wrong-hash-key-type ()
   "Check that Bug#42113 is fixed."
-  (skip-unless (fboundp 'json-serialize))
   (let ((table (make-hash-table :test #'eq)))
     (puthash 1 2 table)
     (should-error (json-serialize table) :type 'wrong-type-argument)))



reply via email to

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