|
1 | 1 | (ns rewrite-clj.custom-zipper.core-test
|
2 |
| - (:require [clojure.test :refer [deftest is are]] |
| 2 | + (:require [clojure.test :refer [deftest is]] |
3 | 3 | #?(:cljs [clojure.test.check :refer-macros [quick-check]])
|
4 | 4 | [clojure.test.check.clojure-test :refer [defspec]]
|
5 | 5 | [clojure.test.check.generators :as gen]
|
|
14 | 14 | (is (= [1 1] (z/position (z/custom-zipper (node/comment-node "hello"))))))
|
15 | 15 |
|
16 | 16 | (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))))) |
25 | 25 |
|
26 | 26 | (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)))))) |
35 | 35 |
|
36 | 36 | (deftest t-zrightmost-tracks-position-correctly
|
37 | 37 | (let [root (base/of-string "[hello world]" {:track-position? true})]
|
38 | 38 | (is (= [1 8] (-> root z/down z/rightmost z/position)))))
|
39 | 39 |
|
40 | 40 | (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)))))) |
48 | 48 |
|
49 | 49 | (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)))))) |
63 | 63 |
|
64 | 64 | (deftest t-zleftmost-tracks-position-correctly
|
65 | 65 | (is (= [1 2]
|
|
89 | 89 | z/position))))
|
90 | 90 |
|
91 | 91 | (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))))))) |
98 | 98 |
|
99 | 99 | (def operations
|
100 | 100 | {:left z/left
|
|
0 commit comments