Skip to content

Commit 76e5c23

Browse files
author
Yannick Scherer
committed
Use 'clojure.test' instead of 'midje'
1 parent af04936 commit 76e5c23

22 files changed

+1284
-1331
lines changed

project.clj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
:repositories {"sonatype-oss-public" "https://oss.sonatype.org/content/groups/public/"}
99
:dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
1010
[org.clojure/tools.reader "1.2.2"]]
11-
:profiles {:dev {:dependencies [[midje "1.8.3" :exclusions [joda-time]]
12-
[joda-time "2.9.9"]
13-
[org.clojure/test.check "0.9.0"]]
14-
:plugins [[lein-midje "3.1.3"]
15-
[codox "0.8.10"]]
11+
:profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]
12+
:plugins [[codox "0.8.10"]]
1613
:exclusions [org.clojure/clojure]
1714
:codox {:project {:name "rewrite-clj"}
1815
:defaults {:doc/format :markdown}}}
1916
:1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
2017
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
2118
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}}
2219
:aliases {"all" ["with-profile" "dev,1.5:dev,1.6:dev,1.7"]
23-
"test" ["midje"]
2420
"test-ancient" ["with-profile" "dev,1.5:dev,1.6:dev,1.7" "midje"]}
2521
:pedantic? :abort)
Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,103 @@
11
(ns rewrite-clj.custom-zipper.core-test
22
(:require [clojure.test.check
3-
[generators :as gen]
4-
[properties :as prop]]
5-
[midje.sweet :refer :all]
3+
[generators :as gen]
4+
[properties :as prop]]
5+
[clojure.test :refer :all]
66
[rewrite-clj.node :as node]
77
[rewrite-clj.node.generators :as g]
8-
[rewrite-clj.test-helpers :refer :all]
8+
[clojure.test.check.clojure-test :refer :all]
99
[rewrite-clj.zip
10-
[base :as base]
11-
[whitespace :as ws]]
10+
[base :as base]
11+
[whitespace :as ws]]
1212
[rewrite-clj.custom-zipper
1313
[core :as z]
1414
[utils :as u]]))
1515

16-
(fact "zipper starts with position [1 1]"
17-
(z/position (z/custom-zipper (node/comment-node "hello"))) => [1 1])
18-
19-
(tabular
20-
(fact "z/down tracks position correctly"
21-
(-> (z/custom-zipper (?type [(node/token-node "hello")]))
22-
z/down
23-
z/position) => ?pos)
24-
?type ?pos
25-
node/forms-node [1 1]
26-
node/fn-node [1 3]
27-
node/quote-node [1 2])
28-
29-
(tabular
30-
(fact "z/right tracks position correctly"
31-
(let [root (base/of-string "[hello \nworld]" {:track-position? true})
32-
zloc (nth (iterate z/next root) ?n)]
33-
(z/position zloc) => ?pos))
34-
?n ?pos
35-
1 [1 2]
36-
2 [1 7]
37-
3 [1 8]
38-
4 [2 1])
39-
40-
(fact "z/rightmost tracks position correctly"
41-
(let [root (base/of-string "[hello world]" {:track-position? true})]
42-
(-> root z/down z/rightmost z/position) => [1 8]))
43-
44-
(tabular
45-
(fact "z/left tracks position correctly"
46-
(let [root (base/of-string "[hello world]" {:track-position? true})
47-
zloc (nth (iterate z/left (z/rightmost (z/down root))) ?n)]
48-
(z/position zloc) => ?pos))
49-
?n ?pos
50-
0 [1 8]
51-
1 [1 7]
52-
2 [1 2])
53-
54-
(tabular
55-
(fact "z/up tracks position correctly"
56-
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
57-
z/down
58-
z/right z/right
59-
z/down
60-
z/right z/right
61-
z/down)
62-
zloc (nth (iterate z/up bottom) ?n)]
63-
(z/position zloc) => ?pos))
64-
?n ?pos
65-
0 [1 8]
66-
1 [1 7]
67-
2 [1 4]
68-
3 [1 1])
69-
70-
(fact "z/leftmost tracks position correctly"
71-
(-> (base/of-string "[hello world]" {:track-position? true})
72-
z/down
73-
z/right z/right
74-
z/leftmost
75-
z/position) => [1 2])
76-
77-
(fact "z/remove tracks position correctly"
78-
(let [root (base/of-string "[hello world]" {:track-position? true})]
79-
(-> root z/down z/remove z/position) => [1 1]
80-
(-> root z/down z/right z/remove z/position) => [1 2]))
81-
82-
(fact "z/replace doesn't change the current position"
83-
(-> (base/of-string "[hello world]" {:track-position? true})
84-
z/down
85-
(z/replace 'x)
86-
z/position) => [1 2])
87-
88-
(fact "z/insert-right doesn't change the current position"
89-
(-> (base/of-string "[hello world]" {:track-position? true})
90-
z/down
91-
(z/insert-right 'x)
92-
z/position) => [1 2])
93-
94-
(tabular
95-
(fact "z/insert-left fixes the position"
96-
(let [root (base/of-string "[hello world]" {:track-position? true})
97-
zloc (nth (iterate z/right (z/down root)) ?n)]
98-
(z/position (z/insert-left zloc 'x)) => ?pos))
99-
?n ?pos
100-
0 [1 3]
101-
1 [1 8])
16+
(deftest t-zipper-starts-with-position-1-1
17+
(is (= [1 1] (z/position (z/custom-zipper (node/comment-node "hello"))))))
18+
19+
(deftest t-zdown-tracks-position-correctly
20+
(are [?type ?pos]
21+
(is (= ?pos
22+
(-> (z/custom-zipper (?type [(node/token-node "hello")]))
23+
z/down
24+
z/position)))
25+
node/forms-node [1 1]
26+
node/fn-node [1 3]
27+
node/quote-node [1 2]))
28+
29+
(deftest t-zright-tracks-position-correctly
30+
(are [?n ?pos]
31+
(let [root (base/of-string "[hello \nworld]" {:track-position? true})
32+
zloc (nth (iterate z/next root) ?n)]
33+
(is (= ?pos (z/position zloc))))
34+
1 [1 2]
35+
2 [1 7]
36+
3 [1 8]
37+
4 [2 1]))
38+
39+
(deftest t-zrightmost-tracks-position-correctly
40+
(let [root (base/of-string "[hello world]" {:track-position? true})]
41+
(is (= [1 8] (-> root z/down z/rightmost z/position)))))
42+
43+
(deftest t-zleft-tracks-position-correctly
44+
(are [?n ?pos]
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))))
48+
0 [1 8]
49+
1 [1 7]
50+
2 [1 2]))
51+
52+
(deftest t-zup-tracks-position-correctly
53+
(are [?n ?pos]
54+
(let [bottom (-> (base/of-string "[x [y [1]]]" {:track-position? true})
55+
z/down
56+
z/right z/right
57+
z/down
58+
z/right z/right
59+
z/down)
60+
zloc (nth (iterate z/up bottom) ?n)]
61+
(is (= ?pos (z/position zloc))))
62+
0 [1 8]
63+
1 [1 7]
64+
2 [1 4]
65+
3 [1 1]))
66+
67+
(deftest t-zleftmost-tracks-position-correctly
68+
(is (= [1 2]
69+
(-> (base/of-string "[hello world]" {:track-position? true})
70+
z/down
71+
z/right z/right
72+
z/leftmost
73+
z/position))))
74+
75+
(deftest t-zremove-tracks-position-correctly
76+
(let [root (base/of-string "[hello world]" {:track-position? true})]
77+
(is (= [1 1] (-> root z/down z/remove z/position)))
78+
(is (= [1 2] (-> root z/down z/right z/remove z/position)))))
79+
80+
(deftest t-zreplace-doesnt-change-the-current-position
81+
(is (= [1 2]
82+
(-> (base/of-string "[hello world]" {:track-position? true})
83+
z/down
84+
(z/replace 'x)
85+
z/position))))
86+
87+
(deftest t-zinsert-right-doesnt-change-the-current-position
88+
(is (= [1 2]
89+
(-> (base/of-string "[hello world]" {:track-position? true})
90+
z/down
91+
(z/insert-right 'x)
92+
z/position))))
93+
94+
(deftest t-zinsert-left-fixes-the-position
95+
(are [?n ?pos]
96+
(let [root (base/of-string "[hello world]" {:track-position? true})
97+
zloc (nth (iterate z/right (z/down root)) ?n)]
98+
(is (= ?pos (z/position (z/insert-left zloc 'x)))))
99+
0 [1 3]
100+
1 [1 8]))
102101

103102
(def operations
104103
{:left z/left
@@ -162,11 +161,11 @@
162161
:else
163162
(first (node/string (z/node zloc)))))
164163

165-
(property "zipper position always matches row and column in root-string"
164+
(defspec t-zipper-position-always-matches-row-and-column-in-root-string
166165
(prop/for-all [node (g/node)
167166
operations (gen/vector (gen/elements (keys operations)) 1 8)]
168-
(let [zloc (apply-operations
169-
(base/edn* node {:track-position? true})
170-
operations)]
171-
(= (char-here zloc)
172-
(char-at-position (base/root-string zloc) (z/position zloc))))))
167+
(let [zloc (apply-operations
168+
(base/edn* node {:track-position? true})
169+
operations)]
170+
(= (char-here zloc)
171+
(char-at-position (base/root-string zloc) (z/position zloc))))))
Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns rewrite-clj.custom-zipper.utils-test
2-
(:require [midje.sweet :refer :all]
2+
(:require [clojure.test :refer :all]
33
[rewrite-clj.node :as node]
44
[rewrite-clj.zip.base :as base]
55
[rewrite-clj.custom-zipper.core :as z]
@@ -10,48 +10,45 @@
1010
c (node/token-node 'c)
1111
d (node/token-node 'd)
1212
loc (z/down (base/edn* (node/forms-node [a b c d])))]
13-
(fact "about 'remove-right'."
14-
(let [loc' (remove-right loc)]
15-
(base/sexpr loc') => 'a
16-
(base/root-string loc') => "acd"))
17-
(fact "about 'remove-left'."
18-
(let [loc' (-> loc z/right z/right remove-left)]
19-
(base/sexpr loc') => 'c
20-
(base/root-string loc') => "acd"))
21-
(fact "about 'remove-and-move-right'."
22-
(let [loc' (remove-and-move-right (z/right loc))]
23-
(base/sexpr loc') => 'c
24-
(base/root-string loc') => "acd"))
25-
(fact "about 'remove-and-move-left'."
26-
(let [loc' (-> loc z/right remove-and-move-left)]
27-
(base/sexpr loc') => 'a
28-
(base/root-string loc') => "acd")))
13+
(deftest t-remove-right
14+
(let [loc' (remove-right loc)]
15+
(is (= 'a (base/sexpr loc')))
16+
(is (= "acd" (base/root-string loc')))))
17+
(deftest t-remove-left
18+
(let [loc' (-> loc z/right z/right remove-left)]
19+
(is (= 'c (base/sexpr loc')))
20+
(is (= "acd" (base/root-string loc')))))
21+
(deftest t-remove-and-move-right
22+
(let [loc' (remove-and-move-right (z/right loc))]
23+
(is (= 'c (base/sexpr loc')))
24+
(is (= "acd" (base/root-string loc')))))
25+
(deftest t-remove-and-move-left
26+
(let [loc' (-> loc z/right remove-and-move-left)]
27+
(is (= 'a (base/sexpr loc')))
28+
(is (= "acd" (base/root-string loc'))))))
2929

30-
(tabular
31-
(fact "`remove-and-move-left` tracks current position correctly"
32-
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
33-
zloc (nth (iterate z/next root) ?n)]
34-
(z/position (remove-and-move-left zloc)) => ?pos))
35-
?n ?pos
36-
3 [1 3]
37-
5 [1 6]
38-
2 [1 2])
30+
(deftest t-remove-and-move-left-tracks-current-position-correctly
31+
(are [?n ?pos]
32+
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
33+
zloc (nth (iterate z/next root) ?n)]
34+
(is (= ?pos (z/position (remove-and-move-left zloc)))))
35+
3 [1 3]
36+
5 [1 6]
37+
2 [1 2]))
3938

40-
(tabular
41-
(fact "`remove-and-move-right` does not affect position"
42-
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
43-
zloc (nth (iterate z/next root) ?n)]
44-
(z/position (remove-and-move-right zloc)) => ?pos))
45-
?n ?pos
46-
3 [1 4]
47-
1 [1 2]
48-
2 [1 3])
39+
(deftest t-remove-and-move-right-does-not-affect-position
40+
(are [?n ?pos]
41+
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
42+
zloc (nth (iterate z/next root) ?n)]
43+
(is (= ?pos (z/position (remove-and-move-right zloc)))))
44+
3 [1 4]
45+
1 [1 2]
46+
2 [1 3]))
4947

50-
(tabular
51-
(fact "`remove-left` tracks current position correctly"
52-
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
53-
zloc (nth (iterate z/next root) ?n)]
54-
(z/position (remove-left zloc)) => ?pos))
55-
?n ?pos
56-
3 [1 3]
57-
5 [1 6])
48+
(deftest t-remove-left-tracks-current-position-correctly
49+
(are [?n ?pos]
50+
(let [root (base/of-string "[a bb ccc]" {:track-position? true})
51+
zloc (nth (iterate z/next root) ?n)]
52+
(is (= ?pos (z/position (remove-left zloc)))))
53+
3 [1 3]
54+
5 [1 6]))

0 commit comments

Comments
 (0)