Skip to content

Commit f7acb80

Browse files
authored
test: migrate from clojure.test/are -> doseq (#288)
Also add a clj-kondo discouraged-var linter to enforce are-less tests. Closes #287
1 parent 8213325 commit f7acb80

16 files changed

+959
-1017
lines changed

.clj-kondo/config.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
rewrite-clj.zip.subedit/edit->> clojure.core/->>
1313
rewrite-clj.custom-zipper.switchable/defn-switchable clojure.core/defn}
1414
:linters
15-
{:redundant-str-call {:level :warning}
15+
{:discouraged-var {clojure.test/are {:message "We're not fans of clojure.test/are, use doseq instead"}}
16+
:redundant-str-call {:level :warning}
1617
:redundant-fn-wrapper {:level :warning}
1718
:unused-value {:level :warning}
1819
:aliased-namespace-symbol {:level :warning}

test/rewrite_clj/custom_zipper/core_test.cljc

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns rewrite-clj.custom-zipper.core-test
2-
(:require [clojure.test :refer [deftest is are]]
2+
(:require [clojure.test :refer [deftest is]]
33
#?(:cljs [clojure.test.check :refer-macros [quick-check]])
44
[clojure.test.check.clojure-test :refer [defspec]]
55
[clojure.test.check.generators :as gen]
@@ -14,52 +14,52 @@
1414
(is (= [1 1] (z/position (z/custom-zipper (node/comment-node "hello"))))))
1515

1616
(deftest t-zdown-tracks-position-correctly
17-
(are [?type ?pos]
18-
(is (= ?pos
19-
(-> (z/custom-zipper (?type [(node/token-node "hello")]))
20-
z/down
21-
z/position)))
22-
node/forms-node [1 1]
23-
node/fn-node [1 3]
24-
node/quote-node [1 2]))
17+
(doseq [[create-fn pos]
18+
[[node/forms-node [1 1]]
19+
[node/fn-node [1 3]]
20+
[node/quote-node [1 2]]]]
21+
(is (= pos
22+
(-> (z/custom-zipper (create-fn [(node/token-node "hello")]))
23+
z/down
24+
z/position)))))
2525

2626
(deftest t-zright-tracks-position-correctly
27-
(are [?n ?pos]
28-
(let [root (base/of-string "[hello \nworld]" {:track-position? true})
29-
zloc (nth (iterate z/next root) ?n)]
30-
(is (= ?pos (z/position zloc))))
31-
1 [1 2]
32-
2 [1 7]
33-
3 [1 8]
34-
4 [2 1]))
27+
(doseq [[n pos]
28+
[[1 [1 2]]
29+
[2 [1 7]]
30+
[3 [1 8]]
31+
[4 [2 1]]]]
32+
(let [root (base/of-string "[hello \nworld]" {:track-position? true})
33+
zloc (nth (iterate z/next root) n)]
34+
(is (= pos (z/position zloc))))))
3535

3636
(deftest t-zrightmost-tracks-position-correctly
3737
(let [root (base/of-string "[hello world]" {:track-position? true})]
3838
(is (= [1 8] (-> root z/down z/rightmost z/position)))))
3939

4040
(deftest t-zleft-tracks-position-correctly
41-
(are [?n ?pos]
42-
(let [root (base/of-string "[hello world]" {:track-position? true})
43-
zloc (nth (iterate z/left (z/rightmost (z/down root))) ?n)]
44-
(is (= ?pos (z/position zloc))))
45-
0 [1 8]
46-
1 [1 7]
47-
2 [1 2]))
41+
(doseq [[n pos]
42+
[[0 [1 8]]
43+
[1 [1 7]]
44+
[2 [1 2]]]]
45+
(let [root (base/of-string "[hello world]" {:track-position? true})
46+
zloc (nth (iterate z/left (z/rightmost (z/down root))) n)]
47+
(is (= pos (z/position zloc))))))
4848

4949
(deftest t-zup-tracks-position-correctly
50-
(are [?n ?pos]
51-
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
52-
z/down
53-
z/right z/right
54-
z/down
55-
z/right z/right
56-
z/down)
57-
zloc (nth (iterate z/up bottom) ?n)]
58-
(is (= ?pos (z/position zloc))))
59-
0 [1 8]
60-
1 [1 7]
61-
2 [1 4]
62-
3 [1 1]))
50+
(doseq [[n pos]
51+
[[0 [1 8]]
52+
[1 [1 7]]
53+
[2 [1 4]]
54+
[3 [1 1]]]]
55+
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
56+
z/down
57+
z/right z/right
58+
z/down
59+
z/right z/right
60+
z/down)
61+
zloc (nth (iterate z/up bottom) n)]
62+
(is (= pos (z/position zloc))))))
6363

6464
(deftest t-zleftmost-tracks-position-correctly
6565
(is (= [1 2]
@@ -89,12 +89,12 @@
8989
z/position))))
9090

9191
(deftest t-zinsert-left-fixes-the-position
92-
(are [?n ?pos]
93-
(let [root (base/of-string "[hello world]" {:track-position? true})
94-
zloc (nth (iterate z/right (z/down root)) ?n)]
95-
(is (= ?pos (z/position (z/insert-left zloc 'x)))))
96-
0 [1 3]
97-
1 [1 8]))
92+
(doseq [[n pos]
93+
[[0 [1 3]]
94+
[1 [1 8]]]]
95+
(let [root (base/of-string "[hello world]" {:track-position? true})
96+
zloc (nth (iterate z/right (z/down root)) n)]
97+
(is (= pos (z/position (z/insert-left zloc 'x)))))))
9898

9999
(def operations
100100
{:left z/left

test/rewrite_clj/examples/cljx_test.cljc

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns rewrite-clj.examples.cljx-test
2-
(:require [clojure.test :refer [deftest is are]]
2+
(:require [clojure.test :refer [deftest is]]
33
[rewrite-clj.zip :as z]))
44

55
;; ## Reader Macro Detection
@@ -17,13 +17,13 @@
1717
(.startsWith nm "-")))))))))
1818

1919
(deftest t-cljx-macro-detection
20-
(are [?data ?pred]
21-
(let [loc (z/of-string ?data)]
22-
(is (?pred (cljx-macro? loc))))
23-
"#+clj 123" identity
24-
"#-clj 123" identity
25-
"#clj 123" not
26-
"123" not))
20+
(doseq [[data pred]
21+
[["#+clj 123" identity]
22+
["#-clj 123" identity]
23+
["#clj 123" not]
24+
["123" not]]]
25+
(let [loc (z/of-string data)]
26+
(is (pred (cljx-macro? loc))))))
2727

2828
;; ## Replace Form w/ Spaces
2929

@@ -74,14 +74,14 @@
7474
(remove-reader-macro-symbol zloc))))
7575

7676
(deftest t-reader-macro-handling
77-
(are [?data ?result]
78-
(let [loc (z/of-string ?data)
79-
rloc (handle-reader-macro #{"clj"} loc)]
80-
(is (= ?result (z/root-string rloc))))
81-
"#+clj 123" " 123"
82-
"#-clj 123" " "
83-
"#+clx 123" " "
84-
"#-clx 123" " 123"))
77+
(doseq [[data result]
78+
[["#+clj 123" " 123"]
79+
["#-clj 123" " "]
80+
["#+clx 123" " "]
81+
["#-clx 123" " 123"]]]
82+
(let [loc (z/of-string data)
83+
rloc (handle-reader-macro #{"clj"} loc)]
84+
(is (= result (z/root-string rloc))))))
8585

8686
;; ## cljx
8787

@@ -106,22 +106,22 @@
106106
" [x]\n"
107107
" #+debug (println #-compact :debug 'inc x)\n"
108108
" (inc x))")]
109-
(are [?profiles ?result]
110-
(is (= ?result (cljx-string data ?profiles)))
111-
#{}
112-
(str "(defn debug-inc\n"
113-
" [x]\n"
114-
" \n"
115-
" (inc x))")
116-
117-
#{:debug}
118-
(str "(defn debug-inc\n"
119-
" [x]\n"
120-
" (println :debug 'inc x)\n"
121-
" (inc x))")
122-
123-
#{:debug :compact}
124-
(str "(defn debug-inc\n"
125-
" [x]\n"
126-
" (println 'inc x)\n"
127-
" (inc x))"))))
109+
(doseq [[profiles result]
110+
[[#{}
111+
(str "(defn debug-inc\n"
112+
" [x]\n"
113+
" \n"
114+
" (inc x))")]
115+
116+
[#{:debug}
117+
(str "(defn debug-inc\n"
118+
" [x]\n"
119+
" (println :debug 'inc x)\n"
120+
" (inc x))")]
121+
122+
[#{:debug :compact}
123+
(str "(defn debug-inc\n"
124+
" [x]\n"
125+
" (println 'inc x)\n"
126+
" (inc x))")]]]
127+
(is (= result (cljx-string data profiles))))))

0 commit comments

Comments
 (0)