diff options
author | João Távora <joaotavora@gmail.com> | 2018-06-02 00:23:38 +0100 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2018-06-07 12:30:39 +0100 |
commit | 3509aaaefe1996ea46b038850629b6d2f7a726fe (patch) | |
tree | 651fec98d47d8c77863f6f0b08c9b3c9c6ac2362 /test/src/json-tests.el | |
parent | 2e2f61efa66b69fbd12c83bbd5370a4be2374f66 (diff) | |
download | emacs-3509aaaefe1996ea46b038850629b6d2f7a726fe.tar.gz |
Accept plists when serializing and parsing JSON
* doc/lispref/text.texi (Parsing JSON): Mention plist support.
* src/json.c (lisp_to_json_toplevel_1): Serialize plists to json.
(Fjson_serialize): Mention plists in docstring.
(enum json_object_type): Add json_object_plist.
(json_to_lisp): Parse JSON into plists.
(json_parse_object_type): Consider plists.
(Fjson_parse_string): Mention plists in docstring.
(syms_of_json): New Qplist sym_of_json.
(lisp_to_json): Update comment.
* test/src/json-tests.el (json-serialize/object)
(json-parse-string/object): New plist tests.
Diffstat (limited to 'test/src/json-tests.el')
-rw-r--r-- | test/src/json-tests.el | 30 |
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 @@ (should-error (json-serialize '((1 . 2))) :type 'wrong-type-argument) (should-error (json-serialize '((a . 1) . b)) :type 'wrong-type-argument) (should-error (json-serialize '#1=((a . 1) . #1#)) :type 'circular-list) - (should-error (json-serialize '(#1=(a #1#))))) + (should-error (json-serialize '(#1=(a #1#)))) + + (should (equal (json-serialize '(:abc [1 2 t] :def :null)) + "{\"abc\":[1,2,true],\"def\":null}")) + (should (equal (json-serialize '(abc [1 2 t] :def :null)) + "{\"abc\":[1,2,true],\"def\":null}")) + (should-error (json-serialize '#1=(:a 1 . #1#)) :type 'circular-list) + (should-error (json-serialize '#1=(:a 1 :b . #1#)) :type 'circular-list) + (should-error (json-serialize '(:foo "bar" (unexpected-alist-key . 1))) + :type 'wrong-type-argument) + (should-error (json-serialize '((abc . "abc") :unexpected-plist-key "key")) + :type 'wrong-type-argument) + (should-error (json-serialize '(:foo bar :odd-numbered)) + :type 'wrong-type-argument) + (should (equal + (json-serialize + (list :detect-hash-table #s(hash-table test equal data ("bla" "ble")) + :detect-alist `((bla . "ble")) + :detect-plist `(:bla "ble"))) + "\ +{\ +\"detect-hash-table\":{\"bla\":\"ble\"},\ +\"detect-alist\":{\"bla\":\"ble\"},\ +\"detect-plist\":{\"bla\":\"ble\"}\ +}"))) (ert-deftest json-serialize/object-with-duplicate-keys () (skip-unless (fboundp 'json-serialize)) @@ -89,7 +113,9 @@ (should (equal (cl-sort (map-pairs actual) #'string< :key #'car) '(("abc" . [9 :false]) ("def" . :null))))) (should (equal (json-parse-string input :object-type 'alist) - '((abc . [9 :false]) (def . :null)))))) + '((abc . [9 :false]) (def . :null)))) + (should (equal (json-parse-string input :object-type 'plist) + '(:abc [9 :false] :def :null))))) (ert-deftest json-parse-string/string () (skip-unless (fboundp 'json-parse-string)) |