aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorJoão Távora2018-06-08 02:35:50 +0100
committerJoão Távora2018-06-15 00:13:00 +0100
commit51adab5de24b3ee215fe636aedb7ff91d69a220c (patch)
tree8664618622113e4890c574d07fa2e025424b951b /test/src
parent9348039ed45c8e493e8bfef0220249d4d31ef6da (diff)
downloademacs-51adab5de24b3ee215fe636aedb7ff91d69a220c.tar.gz
emacs-51adab5de24b3ee215fe636aedb7ff91d69a220c.zip
Also allow custom false and null when serializing to JSON
* doc/lispref/text.texi (Parsing JSON): Describe new arguments of json-serialize and json-insert. * src/json.c (enum json_object_type, struct json_configuration): Move up in file before first usage. (lisp_to_json_toplevel, lisp_to_json_toplevel_1, lisp_to_json): Accept a struct json_configuration*. (Fjson_serialize, Fjson_insert): Accept multiple args. (json_parse_args): Accept new boolean configure_object_type. * test/src/json-tests.el (json-serialize, json-insert): Update forward decls. (json-parse-with-custom-null-and-false-objects): Add assertions for json-serialize.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/json-tests.el18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 918b2336d0f..ffa6fe19f9b 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -26,8 +26,8 @@
26(require 'cl-lib) 26(require 'cl-lib)
27(require 'map) 27(require 'map)
28 28
29(declare-function json-serialize "json.c" (object)) 29(declare-function json-serialize "json.c" (object &rest args))
30(declare-function json-insert "json.c" (object)) 30(declare-function json-insert "json.c" (object &rest args))
31(declare-function json-parse-string "json.c" (string &rest args)) 31(declare-function json-parse-string "json.c" (string &rest args))
32(declare-function json-parse-buffer "json.c" (&rest args)) 32(declare-function json-parse-buffer "json.c" (&rest args))
33 33
@@ -210,8 +210,10 @@ Test with both unibyte and multibyte strings."
210 (should (looking-at-p (rx " [456]" eos))))) 210 (should (looking-at-p (rx " [456]" eos)))))
211 211
212(ert-deftest json-parse-with-custom-null-and-false-objects () 212(ert-deftest json-parse-with-custom-null-and-false-objects ()
213 (let ((input 213 (let* ((input
214 "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n")) 214 "{ \"abc\" : [9, false] , \"def\" : null }")
215 (output
216 (replace-regexp-in-string " " "" input)))
215 (should (equal (json-parse-string input 217 (should (equal (json-parse-string input
216 :object-type 'plist 218 :object-type 'plist
217 :null-object :json-null 219 :null-object :json-null
@@ -236,7 +238,13 @@ Test with both unibyte and multibyte strings."
236 :false-object thingy 238 :false-object thingy
237 :null-object nil))) 239 :null-object nil)))
238 (should (equal retval `((abc . [9 ,thingy]) (def)))) 240 (should (equal retval `((abc . [9 ,thingy]) (def))))
239 (should (eq (elt (cdr (car retval)) 1) thingy))))) 241 (should (eq (elt (cdr (car retval)) 1) thingy)))
242 (should (equal output
243 (json-serialize '((abc . [9 :myfalse]) (def . :mynull))
244 :false-object :myfalse
245 :null-object :mynull)))
246 ;; :object-type is not allowed in json-serialize
247 (should-error (json-serialize '() :object-type 'alist))))
240 248
241(ert-deftest json-insert/signal () 249(ert-deftest json-insert/signal ()
242 (skip-unless (fboundp 'json-insert)) 250 (skip-unless (fboundp 'json-insert))