summaryrefslogtreecommitdiff
path: root/test/src/json-tests.el
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2018-02-03 21:14:59 +0100
committerPhilipp Stephani <phst@google.com>2018-02-03 21:14:59 +0100
commita34c7d7470d5f749659658943bd4084942d873e3 (patch)
tree03c750389e17d359dc0a06589b914ab4c075ea30 /test/src/json-tests.el
parent9da8da2c4105a28064b1b7d3880ae3fc831c7e8a (diff)
downloademacs-a34c7d7470d5f749659658943bd4084942d873e3.tar.gz
Add tests to verify error propagation in 'json-insert'.
* test/src/json-tests.el (json-tests--error): New error symbol. (json-insert/signal, json-insert/throw): New tests.
Diffstat (limited to 'test/src/json-tests.el')
-rw-r--r--test/src/json-tests.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 47bccbe6f3e..3bbf9eb96b0 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -26,6 +26,8 @@
(require 'cl-lib)
(require 'map)
+(define-error 'json-tests--error "JSON test error")
+
(ert-deftest json-serialize/roundtrip ()
(skip-unless (fboundp 'json-serialize))
;; The noncharacter U+FFFF should be passed through,
@@ -176,5 +178,35 @@ Test with both unibyte and multibyte strings."
(should-not (bobp))
(should (looking-at-p (rx " [456]" eos)))))
+(ert-deftest json-insert/signal ()
+ (skip-unless (fboundp 'json-insert))
+ (with-temp-buffer
+ (let ((calls 0))
+ (add-hook 'after-change-functions
+ (lambda (_begin _end _length)
+ (cl-incf calls)
+ (signal 'json-tests--error
+ '("Error in `after-change-functions'")))
+ :local)
+ (should-error
+ (json-insert '((a . "b") (c . 123) (d . [1 2 t :false])))
+ :type 'json-tests--error)
+ (should (equal calls 1)))))
+
+(ert-deftest json-insert/throw ()
+ (skip-unless (fboundp 'json-insert))
+ (with-temp-buffer
+ (let ((calls 0))
+ (add-hook 'after-change-functions
+ (lambda (_begin _end _length)
+ (cl-incf calls)
+ (throw 'test-tag 'throw-value))
+ :local)
+ (should-error
+ (catch 'test-tag
+ (json-insert '((a . "b") (c . 123) (d . [1 2 t :false]))))
+ :type 'no-catch)
+ (should (equal calls 1)))))
+
(provide 'json-tests)
;;; json-tests.el ends here