summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordpsutton <dpsutton@users.noreply.github.com>2018-06-19 15:46:22 -0500
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2018-06-19 23:46:22 +0300
commit499be1067a020daf2a0479f2276e0a257f1dd49d (patch)
tree77f235be3d5916f958b67d4f77c6136aacd66ae6 /test
parenteea7e6e1402d4640f1515177a48ca0fefea18ca4 (diff)
Eval top level defuns inside comment forms (#2323)
Since this is a sensitive codepath (cider-defun-at-point), it is risky to change its behavior due to introducing bugs or introducing unexpected behavior. This _should_ only affect evaluation inside a comment form but we want to be careful. Therefore there is a defcustom `cider-eval-toplevel-inside-comment-form` while others test this. If there is a bug, it is easy for users to turn this feature off completely.
Diffstat (limited to 'test')
-rw-r--r--test/cider-util-tests.el67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/cider-util-tests.el b/test/cider-util-tests.el
index 592d72ef..db23adcd 100644
--- a/test/cider-util-tests.el
+++ b/test/cider-util-tests.el
@@ -126,6 +126,73 @@
(insert "'")
(expect (cider-sexp-at-point 'bounds) :to-equal '(5 15))))))
+(defmacro cider-buffer-with-text
+ (text &rest body)
+ "Run body in a temporary clojure buffer with TEXT.
+TEXT is a string with a | indicating where point is. The | will be erased
+and point left there."
+ (declare (indent 2))
+ `(progn
+ (with-temp-buffer
+ (erase-buffer)
+ (clojure-mode)
+ (insert ,text)
+ (goto-char (point-min))
+ (re-search-forward "|")
+ (delete-char -1)
+ ,@body)))
+
+(describe "cider-defun-inside-comment-form"
+ (describe "when param 'bounds is not given"
+ (it "returns the form containing point"
+ (cider-buffer-with-text
+ "(comment
+ (wrong)
+ (wrong)
+ (rig|ht)
+ (wrong))"
+ (expect (cider-defun-inside-comment-form) :to-equal "(right)")))
+ (it "attaches to the previous top level comment"
+ (cider-buffer-with-text
+ "(comment
+ (wrong)
+ (wrong)
+ (right) |
+ (wrong))"
+ (expect (cider-defun-inside-comment-form) :to-equal "(right)")))
+ (it "attaches to the next top level comment even if its on the same line"
+ (cider-buffer-with-text
+ "(comment
+ (wrong)
+ (wrong)
+ (right)
+ | (wrong))"
+ (expect (cider-defun-inside-comment-form) :to-equal "(right)")))
+ (it "returns the top level even if heavily nested"
+ (cider-buffer-with-text
+ "(comment
+ (wrong)
+ (wrong)
+ (((((r|ight)))))
+ (wrong))"
+ (expect (cider-defun-inside-comment-form) :to-equal "(((((right)))))")))
+ (it "works even on the last form in a comment"
+ (cider-buffer-with-text
+ "(comment
+ (wrong)
+ (wrong)
+ (right|))"
+ (expect (cider-defun-inside-comment-form) :to-equal "(right)")))
+ (it "works on the last form even after the comment form"
+ (cider-buffer-with-text
+ "(comment (wrong) (wrong) (right)) |"
+ (expect (cider-defun-inside-comment-form) :to-equal "(right)"))))
+ (describe "returns entire comment form when"
+ (it "the comment form is empty"
+ (cider-buffer-with-text
+ "(comment|)"
+ (expect (cider-defun-inside-comment-form) :to-equal "(comment)")))))
+
(describe "cider-defun-at-point"
(describe "when the param 'bounds is not given"
(it "returns the defun at point"