aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/json-tests.el30
1 files changed, 28 insertions, 2 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 09067bad8c8..7a193545b1a 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -69,7 +69,31 @@
69 (should-error (json-serialize '((1 . 2))) :type 'wrong-type-argument) 69 (should-error (json-serialize '((1 . 2))) :type 'wrong-type-argument)
70 (should-error (json-serialize '((a . 1) . b)) :type 'wrong-type-argument) 70 (should-error (json-serialize '((a . 1) . b)) :type 'wrong-type-argument)
71 (should-error (json-serialize '#1=((a . 1) . #1#)) :type 'circular-list) 71 (should-error (json-serialize '#1=((a . 1) . #1#)) :type 'circular-list)
72 (should-error (json-serialize '(#1=(a #1#))))) 72 (should-error (json-serialize '(#1=(a #1#))))
73
74 (should (equal (json-serialize '(:abc [1 2 t] :def :null))
75 "{\"abc\":[1,2,true],\"def\":null}"))
76 (should (equal (json-serialize '(abc [1 2 t] :def :null))
77 "{\"abc\":[1,2,true],\"def\":null}"))
78 (should-error (json-serialize '#1=(:a 1 . #1#)) :type 'circular-list)
79 (should-error (json-serialize '#1=(:a 1 :b . #1#)) :type 'circular-list)
80 (should-error (json-serialize '(:foo "bar" (unexpected-alist-key . 1)))
81 :type 'wrong-type-argument)
82 (should-error (json-serialize '((abc . "abc") :unexpected-plist-key "key"))
83 :type 'wrong-type-argument)
84 (should-error (json-serialize '(:foo bar :odd-numbered))
85 :type 'wrong-type-argument)
86 (should (equal
87 (json-serialize
88 (list :detect-hash-table #s(hash-table test equal data ("bla" "ble"))
89 :detect-alist `((bla . "ble"))
90 :detect-plist `(:bla "ble")))
91 "\
92{\
93\"detect-hash-table\":{\"bla\":\"ble\"},\
94\"detect-alist\":{\"bla\":\"ble\"},\
95\"detect-plist\":{\"bla\":\"ble\"}\
96}")))
73 97
74(ert-deftest json-serialize/object-with-duplicate-keys () 98(ert-deftest json-serialize/object-with-duplicate-keys ()
75 (skip-unless (fboundp 'json-serialize)) 99 (skip-unless (fboundp 'json-serialize))
@@ -89,7 +113,9 @@
89 (should (equal (cl-sort (map-pairs actual) #'string< :key #'car) 113 (should (equal (cl-sort (map-pairs actual) #'string< :key #'car)
90 '(("abc" . [9 :false]) ("def" . :null))))) 114 '(("abc" . [9 :false]) ("def" . :null)))))
91 (should (equal (json-parse-string input :object-type 'alist) 115 (should (equal (json-parse-string input :object-type 'alist)
92 '((abc . [9 :false]) (def . :null)))))) 116 '((abc . [9 :false]) (def . :null))))
117 (should (equal (json-parse-string input :object-type 'plist)
118 '(:abc [9 :false] :def :null)))))
93 119
94(ert-deftest json-parse-string/string () 120(ert-deftest json-parse-string/string ()
95 (skip-unless (fboundp 'json-parse-string)) 121 (skip-unless (fboundp 'json-parse-string))