aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJoão Távora2018-06-07 17:41:19 +0100
committerJoão Távora2018-06-15 00:11:56 +0100
commit9348039ed45c8e493e8bfef0220249d4d31ef6da (patch)
treee7f79a9013d4b80bfb6b980a216419662f982866 /test
parent8cb9beb32163fa3ce3b052ced646fd673814ddc6 (diff)
downloademacs-9348039ed45c8e493e8bfef0220249d4d31ef6da.tar.gz
emacs-9348039ed45c8e493e8bfef0220249d4d31ef6da.zip
Support custom null and false objects when parsing JSON
* doc/lispref/text.texi (Parsing JSON): Describe new :null-object and :false-object kwargs to json-parse-string and json-parse-buffer. * src/json.c (struct json_configuration): New type. (json_to_lisp): Accept a struct json_configuration* param. (json_parse_args): Rename from json_parse_object_type. (Fjson_parse_string): Rework docstring. (Fjson_parse_string, Fjson_parse_buffer): Update call to json_to_lisp. (syms_of_json): Two new syms, QCnull_object and QCfalse_object. * test/src/json-tests.el (json-parse-with-custom-null-and-false-objects): New test.
Diffstat (limited to 'test')
-rw-r--r--test/src/json-tests.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 7a193545b1a..918b2336d0f 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -209,6 +209,35 @@ Test with both unibyte and multibyte strings."
209 (should-not (bobp)) 209 (should-not (bobp))
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 ()
213 (let ((input
214 "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n"))
215 (should (equal (json-parse-string input
216 :object-type 'plist
217 :null-object :json-null
218 :false-object :json-false)
219 '(:abc [9 :json-false] :def :json-null)))
220 (should (equal (json-parse-string input
221 :object-type 'plist
222 :false-object :json-false)
223 '(:abc [9 :json-false] :def :null)))
224 (should (equal (json-parse-string input
225 :object-type 'alist
226 :null-object :zilch)
227 '((abc . [9 :false]) (def . :zilch))))
228 (should (equal (json-parse-string input
229 :object-type 'alist
230 :false-object nil
231 :null-object nil)
232 '((abc . [9 nil]) (def))))
233 (let* ((thingy '(1 2 3))
234 (retval (json-parse-string input
235 :object-type 'alist
236 :false-object thingy
237 :null-object nil)))
238 (should (equal retval `((abc . [9 ,thingy]) (def))))
239 (should (eq (elt (cdr (car retval)) 1) thingy)))))
240
212(ert-deftest json-insert/signal () 241(ert-deftest json-insert/signal ()
213 (skip-unless (fboundp 'json-insert)) 242 (skip-unless (fboundp 'json-insert))
214 (with-temp-buffer 243 (with-temp-buffer