|
25 | 25 | ;;; Code: |
26 | 26 |
|
27 | 27 | (require 'clojure-mode) |
28 | | -(require 'ert) |
| 28 | +(require 'test-helper) |
| 29 | +(require 'buttercup) |
29 | 30 |
|
30 | | -(def-refactor-test test-cycle-privacy-public-defn-private-defn |
31 | | - "(defn add [a b] |
| 31 | +(describe "clojure-cycle-privacy" |
| 32 | + |
| 33 | + (when-refactoring-it "should turn a public defn into a private defn" |
| 34 | + "(defn add [a b] |
32 | 35 | (+ a b))" |
33 | | - "(defn- add [a b] |
| 36 | + |
| 37 | + "(defn- add [a b] |
34 | 38 | (+ a b))" |
35 | | - (clojure-cycle-privacy)) |
36 | 39 |
|
37 | | -(def-refactor-test test-cycle-privacy-from-sexp-beg |
38 | | - "(defn- add [a b] |
| 40 | + (clojure-cycle-privacy)) |
| 41 | + |
| 42 | + (when-refactoring-it "should also work from the beginning of a sexp" |
| 43 | + "(defn- add [a b] |
39 | 44 | (+ a b))" |
40 | | - "(defn add [a b] |
| 45 | + |
| 46 | + "(defn add [a b] |
41 | 47 | (+ a b))" |
42 | | - (backward-sexp) |
43 | | - (clojure-cycle-privacy)) |
44 | 48 |
|
45 | | -(def-refactor-test test-cycle-privacy-public-defn-private-defn-metadata |
46 | | - "(defn add [a b] |
| 49 | + (backward-sexp) |
| 50 | + (clojure-cycle-privacy)) |
| 51 | + |
| 52 | + (when-refactoring-it "should use metadata when clojure-use-metadata-for-privacy is set to true" |
| 53 | + "(defn add [a b] |
47 | 54 | (+ a b))" |
48 | | - "(defn ^:private add [a b] |
| 55 | + |
| 56 | + "(defn ^:private add [a b] |
49 | 57 | (+ a b))" |
50 | | - (let ((clojure-use-metadata-for-privacy t)) |
| 58 | + |
| 59 | + (let ((clojure-use-metadata-for-privacy t)) |
51 | 60 | (clojure-cycle-privacy))) |
52 | 61 |
|
53 | | -(def-refactor-test test-cycle-privacy-private-defn-public-defn |
54 | | - "(defn- add [a b] |
| 62 | + (when-refactoring-it "should turn a private defn into a public defn" |
| 63 | + "(defn- add [a b] |
55 | 64 | (+ a b))" |
56 | | - "(defn add [a b] |
| 65 | + |
| 66 | + "(defn add [a b] |
57 | 67 | (+ a b))" |
58 | | - (clojure-cycle-privacy)) |
59 | 68 |
|
60 | | -(def-refactor-test test-cycle-privacy-private-defn-public-defn-metadata |
61 | | - "(defn ^:private add [a b] |
| 69 | + (clojure-cycle-privacy)) |
| 70 | + |
| 71 | + (when-refactoring-it "should turn a private defn with metadata into a public defn" |
| 72 | + "(defn ^:private add [a b] |
62 | 73 | (+ a b))" |
63 | | - "(defn add [a b] |
| 74 | + |
| 75 | + "(defn add [a b] |
64 | 76 | (+ a b))" |
65 | | - (let ((clojure-use-metadata-for-privacy t)) |
66 | | - (clojure-cycle-privacy))) |
67 | 77 |
|
68 | | -(def-refactor-test test-cycle-privacy-public-def-private-def |
69 | | - "(def ^:dynamic config |
| 78 | + (let ((clojure-use-metadata-for-privacy t)) |
| 79 | + (clojure-cycle-privacy))) |
| 80 | + |
| 81 | + (when-refactoring-it "should also work with pre-existing metadata" |
| 82 | + "(def ^:dynamic config |
70 | 83 | \"docs\" |
71 | 84 | {:env \"staging\"})" |
72 | | - "(def ^:private ^:dynamic config |
| 85 | + |
| 86 | + "(def ^:private ^:dynamic config |
73 | 87 | \"docs\" |
74 | 88 | {:env \"staging\"})" |
75 | | - (clojure-cycle-privacy)) |
76 | 89 |
|
77 | | -(def-refactor-test test-cycle-privacy-private-def-public-def |
78 | | - "(def ^:private config |
| 90 | + (clojure-cycle-privacy)) |
| 91 | + |
| 92 | + (when-refactoring-it "should turn a private def with metadata into a public def" |
| 93 | + "(def ^:private config |
79 | 94 | \"docs\" |
80 | 95 | {:env \"staging\"})" |
81 | | - "(def config |
| 96 | + |
| 97 | + "(def config |
82 | 98 | \"docs\" |
83 | 99 | {:env \"staging\"})" |
84 | | - (clojure-cycle-privacy)) |
85 | 100 |
|
86 | | -(def-refactor-test test-cycle-if-inner-if |
87 | | - "(if this |
| 101 | + (clojure-cycle-privacy))) |
| 102 | + |
| 103 | +(describe "clojure-cycle-if" |
| 104 | + |
| 105 | + (when-refactoring-it "should cycle inner if" |
| 106 | + "(if this |
88 | 107 | (if that |
89 | 108 | (then AAA) |
90 | 109 | (else BBB)) |
91 | 110 | (otherwise CCC))" |
92 | | - "(if this |
| 111 | + |
| 112 | + "(if this |
93 | 113 | (if-not that |
94 | 114 | (else BBB) |
95 | 115 | (then AAA)) |
96 | 116 | (otherwise CCC))" |
97 | | - (beginning-of-buffer) |
98 | | - (search-forward "BBB)") |
99 | | - (clojure-cycle-if)) |
100 | 117 |
|
101 | | -(def-refactor-test test-cycle-if-outer-if |
102 | | - "(if-not this |
| 118 | + (beginning-of-buffer) |
| 119 | + (search-forward "BBB)") |
| 120 | + (clojure-cycle-if)) |
| 121 | + |
| 122 | + (when-refactoring-it "should cycle outer if" |
| 123 | + "(if-not this |
103 | 124 | (if that |
104 | 125 | (then AAA) |
105 | 126 | (else BBB)) |
106 | 127 | (otherwise CCC))" |
107 | | - "(if this |
| 128 | + |
| 129 | + "(if this |
108 | 130 | (otherwise CCC) |
109 | 131 | (if that |
110 | 132 | (then AAA) |
111 | 133 | (else BBB)))" |
112 | | - (beginning-of-buffer) |
113 | | - (search-forward "BBB))") |
114 | | - (clojure-cycle-if)) |
115 | 134 |
|
116 | | -(def-refactor-test test-cycle-when-inner-when |
117 | | - "(when this |
| 135 | + (beginning-of-buffer) |
| 136 | + (search-forward "BBB))") |
| 137 | + (clojure-cycle-if))) |
| 138 | + |
| 139 | +(describe "clojure-cycle-when" |
| 140 | + |
| 141 | + (when-refactoring-it "should cycle inner when" |
| 142 | + "(when this |
118 | 143 | (when that |
119 | 144 | (aaa) |
120 | 145 | (bbb)) |
121 | 146 | (ccc))" |
122 | | - "(when this |
| 147 | + |
| 148 | + "(when this |
123 | 149 | (when-not that |
124 | 150 | (aaa) |
125 | 151 | (bbb)) |
126 | 152 | (ccc))" |
127 | | - (beginning-of-buffer) |
128 | | - (search-forward "bbb)") |
129 | | - (clojure-cycle-when)) |
130 | 153 |
|
131 | | -(def-refactor-test test-cycle-when-outer-when |
132 | | - "(when-not this |
| 154 | + (beginning-of-buffer) |
| 155 | + (search-forward "bbb)") |
| 156 | + (clojure-cycle-when)) |
| 157 | + |
| 158 | + (when-refactoring-it "should cycle outer when" |
| 159 | + "(when-not this |
133 | 160 | (when that |
134 | 161 | (aaa) |
135 | 162 | (bbb)) |
136 | 163 | (ccc))" |
137 | | - "(when this |
| 164 | + |
| 165 | + "(when this |
138 | 166 | (when that |
139 | 167 | (aaa) |
140 | 168 | (bbb)) |
141 | 169 | (ccc))" |
142 | | - (beginning-of-buffer) |
143 | | - (search-forward "bbb))") |
144 | | - (clojure-cycle-when)) |
145 | | - |
146 | | -(def-refactor-test test-cycle-not-add |
147 | | - "(ala bala portokala)" |
148 | | - "(not (ala bala portokala))" |
149 | | - (beginning-of-buffer) |
150 | | - (search-forward "bala") |
151 | | - (clojure-cycle-not)) |
152 | | - |
153 | | -(def-refactor-test test-cycle-not-remove |
154 | | - "(not (ala bala portokala))" |
155 | | - "(ala bala portokala)" |
156 | | - (beginning-of-buffer) |
157 | | - (search-forward "bala") |
158 | | - (clojure-cycle-not)) |
| 170 | + |
| 171 | + (beginning-of-buffer) |
| 172 | + (search-forward "bbb))") |
| 173 | + (clojure-cycle-when))) |
| 174 | + |
| 175 | +(describe "clojure-cycle-not" |
| 176 | + |
| 177 | + (when-refactoring-it "should add a not when missing" |
| 178 | + "(ala bala portokala)" |
| 179 | + "(not (ala bala portokala))" |
| 180 | + |
| 181 | + (beginning-of-buffer) |
| 182 | + (search-forward "bala") |
| 183 | + (clojure-cycle-not)) |
| 184 | + |
| 185 | + (when-refactoring-it "should remove a not when present" |
| 186 | + "(not (ala bala portokala))" |
| 187 | + "(ala bala portokala)" |
| 188 | + |
| 189 | + (beginning-of-buffer) |
| 190 | + (search-forward "bala") |
| 191 | + (clojure-cycle-not))) |
159 | 192 |
|
160 | 193 | (provide 'clojure-mode-cycling-test) |
161 | 194 |
|
|
0 commit comments