Skip to content

Commit

Permalink
test: migrate from clojure.test/are -> doseq (#288)
Browse files Browse the repository at this point in the history
Also add a clj-kondo discouraged-var linter to enforce are-less tests.

Closes #287
  • Loading branch information
lread authored Jun 28, 2024
1 parent 8213325 commit f7acb80
Show file tree
Hide file tree
Showing 16 changed files with 959 additions and 1,017 deletions.
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
rewrite-clj.zip.subedit/edit->> clojure.core/->>
rewrite-clj.custom-zipper.switchable/defn-switchable clojure.core/defn}
:linters
{:redundant-str-call {:level :warning}
{:discouraged-var {clojure.test/are {:message "We're not fans of clojure.test/are, use doseq instead"}}
:redundant-str-call {:level :warning}
:redundant-fn-wrapper {:level :warning}
:unused-value {:level :warning}
:aliased-namespace-symbol {:level :warning}
Expand Down
86 changes: 43 additions & 43 deletions test/rewrite_clj/custom_zipper/core_test.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns rewrite-clj.custom-zipper.core-test
(:require [clojure.test :refer [deftest is are]]
(:require [clojure.test :refer [deftest is]]
#?(:cljs [clojure.test.check :refer-macros [quick-check]])
[clojure.test.check.clojure-test :refer [defspec]]
[clojure.test.check.generators :as gen]
Expand All @@ -14,52 +14,52 @@
(is (= [1 1] (z/position (z/custom-zipper (node/comment-node "hello"))))))

(deftest t-zdown-tracks-position-correctly
(are [?type ?pos]
(is (= ?pos
(-> (z/custom-zipper (?type [(node/token-node "hello")]))
z/down
z/position)))
node/forms-node [1 1]
node/fn-node [1 3]
node/quote-node [1 2]))
(doseq [[create-fn pos]
[[node/forms-node [1 1]]
[node/fn-node [1 3]]
[node/quote-node [1 2]]]]
(is (= pos
(-> (z/custom-zipper (create-fn [(node/token-node "hello")]))
z/down
z/position)))))

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

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

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

(deftest t-zup-tracks-position-correctly
(are [?n ?pos]
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
z/down
z/right z/right
z/down
z/right z/right
z/down)
zloc (nth (iterate z/up bottom) ?n)]
(is (= ?pos (z/position zloc))))
0 [1 8]
1 [1 7]
2 [1 4]
3 [1 1]))
(doseq [[n pos]
[[0 [1 8]]
[1 [1 7]]
[2 [1 4]]
[3 [1 1]]]]
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
z/down
z/right z/right
z/down
z/right z/right
z/down)
zloc (nth (iterate z/up bottom) n)]
(is (= pos (z/position zloc))))))

(deftest t-zleftmost-tracks-position-correctly
(is (= [1 2]
Expand Down Expand Up @@ -89,12 +89,12 @@
z/position))))

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

(def operations
{:left z/left
Expand Down
70 changes: 35 additions & 35 deletions test/rewrite_clj/examples/cljx_test.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns rewrite-clj.examples.cljx-test
(:require [clojure.test :refer [deftest is are]]
(:require [clojure.test :refer [deftest is]]
[rewrite-clj.zip :as z]))

;; ## Reader Macro Detection
Expand All @@ -17,13 +17,13 @@
(.startsWith nm "-")))))))))

(deftest t-cljx-macro-detection
(are [?data ?pred]
(let [loc (z/of-string ?data)]
(is (?pred (cljx-macro? loc))))
"#+clj 123" identity
"#-clj 123" identity
"#clj 123" not
"123" not))
(doseq [[data pred]
[["#+clj 123" identity]
["#-clj 123" identity]
["#clj 123" not]
["123" not]]]
(let [loc (z/of-string data)]
(is (pred (cljx-macro? loc))))))

;; ## Replace Form w/ Spaces

Expand Down Expand Up @@ -74,14 +74,14 @@
(remove-reader-macro-symbol zloc))))

(deftest t-reader-macro-handling
(are [?data ?result]
(let [loc (z/of-string ?data)
rloc (handle-reader-macro #{"clj"} loc)]
(is (= ?result (z/root-string rloc))))
"#+clj 123" " 123"
"#-clj 123" " "
"#+clx 123" " "
"#-clx 123" " 123"))
(doseq [[data result]
[["#+clj 123" " 123"]
["#-clj 123" " "]
["#+clx 123" " "]
["#-clx 123" " 123"]]]
(let [loc (z/of-string data)
rloc (handle-reader-macro #{"clj"} loc)]
(is (= result (z/root-string rloc))))))

;; ## cljx

Expand All @@ -106,22 +106,22 @@
" [x]\n"
" #+debug (println #-compact :debug 'inc x)\n"
" (inc x))")]
(are [?profiles ?result]
(is (= ?result (cljx-string data ?profiles)))
#{}
(str "(defn debug-inc\n"
" [x]\n"
" \n"
" (inc x))")

#{:debug}
(str "(defn debug-inc\n"
" [x]\n"
" (println :debug 'inc x)\n"
" (inc x))")

#{:debug :compact}
(str "(defn debug-inc\n"
" [x]\n"
" (println 'inc x)\n"
" (inc x))"))))
(doseq [[profiles result]
[[#{}
(str "(defn debug-inc\n"
" [x]\n"
" \n"
" (inc x))")]

[#{:debug}
(str "(defn debug-inc\n"
" [x]\n"
" (println :debug 'inc x)\n"
" (inc x))")]

[#{:debug :compact}
(str "(defn debug-inc\n"
" [x]\n"
" (println 'inc x)\n"
" (inc x))")]]]
(is (= result (cljx-string data profiles))))))
Loading

0 comments on commit f7acb80

Please sign in to comment.