Skip to content

Commit bbb8a51

Browse files
yuhan0bbatsov
authored andcommitted
Add tests for toggling ignore forms
1 parent a66c33c commit bbb8a51

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

test/clojure-mode-util-test.el

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
(clojure-mode)
140140
(clojure-sort-ns)
141141
(expect (buffer-string) :to-equal
142-
"\n(ns my-app.core
142+
"\n(ns my-app.core
143143
(:require [my-app.state :refer [state]] ; Comments too.
144144
my-app.util.api
145145
[my-app.views [front-page :as front-page]]
@@ -149,6 +149,91 @@
149149
(:import [clojure.lang AFunction Atom MultiFn Namespace]
150150
java.io.Writer))"))))
151151

152+
(describe "clojure-toggle-ignore"
153+
(when-refactoring-with-point-it "should add #_ to literals"
154+
"[1 |2 3]" "[1 #_|2 3]"
155+
(clojure-toggle-ignore))
156+
(when-refactoring-with-point-it "should work with point in middle of symbol"
157+
"[foo b|ar baz]" "[foo #_b|ar baz]"
158+
(clojure-toggle-ignore))
159+
(when-refactoring-with-point-it "should remove #_ after cursor"
160+
"[1 |#_2 3]" "[1 |2 3]"
161+
(clojure-toggle-ignore))
162+
(when-refactoring-with-point-it "should remove #_ before cursor"
163+
"[#_:fo|o :bar :baz]" "[:fo|o :bar :baz]"
164+
(clojure-toggle-ignore))
165+
(when-refactoring-with-point-it "should insert multiple #_"
166+
"{:foo| 1 :bar 2 :baz 3}"
167+
"{#_#_#_#_:foo| 1 :bar 2 :baz 3}"
168+
(clojure-toggle-ignore 4))
169+
(when-refactoring-with-point-it "should remove multiple #_"
170+
"{#_#_#_#_:foo| 1 :bar 2 :baz 3}"
171+
"{#_#_:foo| 1 :bar 2 :baz 3}"
172+
(clojure-toggle-ignore 2))
173+
(when-refactoring-with-point-it "should handle spaces and newlines"
174+
"[foo #_ \n #_ \r\n b|ar baz]" "[foo b|ar baz]"
175+
(clojure-toggle-ignore 2))
176+
(when-refactoring-with-point-it "should toggle entire string"
177+
"[:div \"lorem ips|um text\"]"
178+
"[:div #_\"lorem ips|um text\"]"
179+
(clojure-toggle-ignore))
180+
(when-refactoring-with-point-it "should toggle regexps"
181+
"[|#\".*\"]"
182+
"[#_|#\".*\"]"
183+
(clojure-toggle-ignore))
184+
(when-refactoring-with-point-it "should toggle collections"
185+
"[foo |[bar baz]]"
186+
"[foo #_|[bar baz]]"
187+
(clojure-toggle-ignore))
188+
(when-refactoring-with-point-it "should toggle hash sets"
189+
"[foo #|{bar baz}]"
190+
"[foo #_#|{bar baz}]"
191+
(clojure-toggle-ignore))
192+
(when-refactoring-with-point-it "should work on last-sexp"
193+
"[foo '(bar baz)| quux]"
194+
"[foo #_'(bar baz)| quux]"
195+
(clojure-toggle-ignore))
196+
(when-refactoring-with-point-it "should insert newline before top-level form"
197+
"|[foo bar baz]"
198+
"#_
199+
|[foo bar baz]"
200+
(clojure-toggle-ignore)))
201+
202+
(describe "clojure-toggle-ignore-surrounding-form"
203+
(when-refactoring-with-point-it "should toggle lists"
204+
"(li|st [vector {map #{set}}])"
205+
"#_\n(li|st [vector {map #{set}}])"
206+
(clojure-toggle-ignore-surrounding-form))
207+
(when-refactoring-with-point-it "should toggle vectors"
208+
"(list #_[vector| {map #{set}}])"
209+
"(list [vector| {map #{set}}])"
210+
(clojure-toggle-ignore-surrounding-form))
211+
(when-refactoring-with-point-it "should toggle maps"
212+
"(list [vector #_ \n {map #{set}|}])"
213+
"(list [vector {map #{set}|}])"
214+
(clojure-toggle-ignore-surrounding-form))
215+
(when-refactoring-with-point-it "should toggle sets"
216+
"(list [vector {map #{set|}}])"
217+
"(list [vector {map #_#{set|}}])"
218+
(clojure-toggle-ignore-surrounding-form))
219+
(when-refactoring-with-point-it "should work with numeric arg"
220+
"(four (three (two (on|e)))"
221+
"(four (three #_(two (on|e)))"
222+
(clojure-toggle-ignore-surrounding-form 2))
223+
(when-refactoring-with-point-it "should remove #_ with numeric arg"
224+
"(four #_(three (two (on|e)))"
225+
"(four (three (two (on|e)))"
226+
(clojure-toggle-ignore-surrounding-form 3)))
227+
228+
(describe "clojure-toggle-ignore-defun"
229+
(when-refactoring-with-point-it "should ignore defun with newline"
230+
"(defn foo [x]
231+
{:nested (in|c x)})"
232+
"#_
233+
(defn foo [x]
234+
{:nested (in|c x)})"
235+
(clojure-toggle-ignore-defun)))
236+
152237
(provide 'clojure-mode-util-test)
153238

154239
;;; clojure-mode-util-test.el ends here

0 commit comments

Comments
 (0)