emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/compat 951558fe89 5/5: Simplify json tests


From: ELPA Syncer
Subject: [elpa] externals/compat 951558fe89 5/5: Simplify json tests
Date: Tue, 3 Jan 2023 19:57:26 -0500 (EST)

branch: externals/compat
commit 951558fe89c21a86a13fa7897f3f48abc45c06ca
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Simplify json tests
---
 compat-27.el    |  9 ++++++---
 compat-tests.el | 20 +++++---------------
 2 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/compat-27.el b/compat-27.el
index 8cecfa5b5b..16c6cf9939 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -161,7 +161,8 @@ any JSON false values."
                (:success t)
                (void-function nil)
                (json-unavailable nil)))
-  (require 'json)
+  (unless (fboundp 'json-encode)
+    (require 'json))
   (letrec ((fix (lambda (obj)
                   (cond
                    ((hash-table-p obj)
@@ -252,7 +253,8 @@ represent a JSON false value.  It defaults to `:false'."
                (:success t)
                (void-function nil)
                (json-unavailable nil)))
-  (require 'json)
+  (unless (fboundp 'json-read-from-string)
+    (require 'json))
   (condition-case err
       (let ((json-object-type (or (plist-get args :object-type) 'hash-table))
             (json-array-type (or (plist-get args :array-type) 'vector))
@@ -296,7 +298,8 @@ represent a JSON false value.  It defaults to `:false'."
                (:success t)
                (void-function nil)
                (json-unavailable nil)))
-  (require 'json)
+  (unless (fboundp 'json-read)
+    (require 'json))
   (condition-case err
       (let ((json-object-type (or (plist-get args :object-type) 'hash-table))
             (json-array-type (or (plist-get args :array-type) 'vector))
diff --git a/compat-tests.el b/compat-tests.el
index 278a06e465..f992fa6eba 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1255,25 +1255,15 @@ being compared against."
 (ert-deftest compat-json-parse-string ()
   "Check if `compat--t-json-parse-string' was implemented properly."
   (let ((input "{\"key\":[\"abc\", 2], \"yek\": null}"))
-    (let ((obj (compat--t-json-parse-string input)))
-      (should (equal (gethash "key" obj) ["abc" 2]))
-      (should (equal (gethash "yek" obj) :null)))
-    (let ((obj (compat--t-json-parse-string input :object-type 'alist)))
+    (let ((obj (json-parse-string input :object-type 'alist)))
       (should (equal (cdr (assq 'key obj)) ["abc" 2]))
       (should (equal (cdr (assq 'yek obj)) :null)))
-    (let ((obj (compat--t-json-parse-string input :object-type 'plist)))
+    (let ((obj (json-parse-string input :object-type 'plist)))
       (should (equal (plist-get obj :key) ["abc" 2]))
       (should (equal (plist-get obj :yek) :null)))
-    (when (fboundp 'json-parse-string)
-      (let ((obj (json-parse-string input :object-type 'alist)))
-        (should (equal (cdr (assq 'key obj)) ["abc" 2]))
-        (should (equal (cdr (assq 'yek obj)) :null)))
-      (let ((obj (json-parse-string input :object-type 'plist)))
-        (should (equal (plist-get obj :key) ["abc" 2]))
-        (should (equal (plist-get obj :yek) :null)))
-      (let ((obj (json-parse-string input)))
-        (should (equal (gethash "key" obj) ["abc" 2]))
-        (should (equal (gethash "yek" obj) :null))))))
+    (let ((obj (json-parse-string input)))
+      (should (equal (gethash "key" obj) ["abc" 2]))
+      (should (equal (gethash "yek" obj) :null)))))
 
 (ert-deftest compat-json-insert ()
   (with-temp-buffer



reply via email to

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