|
155 | 155 | (clojure.string/replace b in-both ""))
|
156 | 156 | "\n"))
|
157 | 157 |
|
| 158 | +(defn ^:no-doc =?-impl |
| 159 | + "Perform comparison of expected vs actual, build :expected and :actual forms." |
| 160 | + [{:keys [e e# a a# conform?]}] |
| 161 | + (cond conform? |
| 162 | + [(s/valid? e# a#) |
| 163 | + (s/explain-str e# a#) |
| 164 | + (list 's/valid? e a) |
| 165 | + (list 'not (list 's/valid? e a#))] |
| 166 | + (fn? e#) |
| 167 | + [(e# a#) |
| 168 | + (str a " did not satisfy " e "\n") |
| 169 | + (list e a) |
| 170 | + (list 'not (list e a#))] |
| 171 | + (isa? (type e#) |
| 172 | + #?(:clj java.util.regex.Pattern |
| 173 | + :cljs (type #"regex"))) |
| 174 | + [(some? (re-find e# a#)) |
| 175 | + (str (pr-str a#) " did not match " (pr-str e#) "\n") |
| 176 | + (list 're-find e a) |
| 177 | + (list 'not (list 're-find e# a#))] |
| 178 | + #?(:clj (and (class? e#) (class? a#)) |
| 179 | + :cljs false) ; maybe figure this out later |
| 180 | + [(isa? a# e#) ; (expect parent child) |
| 181 | + (str a# " is not derived from " e# "\n") |
| 182 | + (list 'isa? a e) |
| 183 | + (list 'not (list 'isa? a# e#))] |
| 184 | + #?(:clj (class? e#) |
| 185 | + :cljs false) ; maybe figure this out later |
| 186 | + [(instance? e# a#) ; (expect klazz object) |
| 187 | + (str a# |
| 188 | + #?(:clj (str " (" (class a#) ")")) |
| 189 | + " is not an instance of " e# "\n") |
| 190 | + (list 'instance? e a) |
| 191 | + #?(:clj (class a#))] |
| 192 | + :else |
| 193 | + [(= e# a#) |
| 194 | + (when (and (string? e#) (string? a#) (not= e# a#)) |
| 195 | + (let [[_# _# in-both#] (str-diff e# a#)] |
| 196 | + (str-msg e# a# in-both#))) |
| 197 | + (list '= e a) |
| 198 | + (list 'not= e# a#)])) |
| 199 | + |
158 | 200 | ;; smart equality extension to clojure.test assertion -- if the expected form
|
159 | 201 | ;; is a predicate (function) then the assertion is equivalent to (is (e a))
|
160 | 202 | ;; rather than (is (= e a)) and we need the type check done at runtime, not
|
|
169 | 211 | `(let [e# ~e
|
170 | 212 | a# ~a
|
171 | 213 | f# ~form'
|
172 |
| - valid?# (when ~conform? s/valid?) |
173 |
| - explain-str?# (when ~conform? s/explain-str) |
174 |
| - [r# m# ef# af#] |
175 |
| - (cond ~conform? |
176 |
| - [(valid?# e# a#) |
177 |
| - (explain-str?# e# a#) |
178 |
| - (list '~'s/valid? '~e '~a) |
179 |
| - (list '~'not (list '~'s/valid? '~e a#))] |
180 |
| - (fn? e#) |
181 |
| - [(e# a#) |
182 |
| - (str '~a " did not satisfy " '~e "\n") |
183 |
| - (list '~e '~a) |
184 |
| - (list '~'not (list '~e a#))] |
185 |
| - (isa? (type e#) |
186 |
| - #?(:clj java.util.regex.Pattern |
187 |
| - :cljs (type #"regex"))) |
188 |
| - [(some? (re-find e# a#)) |
189 |
| - (str (pr-str a#) " did not match " (pr-str e#) "\n") |
190 |
| - (list '~'re-find '~e '~a) |
191 |
| - (list '~'not (list '~'re-find e# a#))] |
192 |
| - #?(:clj (and (class? e#) (class? a#)) |
193 |
| - :cljs false) ; maybe figure this out later |
194 |
| - [(isa? a# e#) ; (expect parent child) |
195 |
| - (str a# " is not derived from " e# "\n") |
196 |
| - (list '~'isa? '~a '~e) |
197 |
| - (list '~'not (list '~'isa? a# e#))] |
198 |
| - #?(:clj (class? e#) |
199 |
| - :cljs false) ; maybe figure this out later |
200 |
| - [(instance? e# a#) ; (expect klazz object) |
201 |
| - (str a# |
202 |
| - #?(:clj (str " (" (class a#) ")")) |
203 |
| - " is not an instance of " e# "\n") |
204 |
| - (list '~'instance? '~e '~a) |
205 |
| - #?(:clj (class a#))] |
206 |
| - :else |
207 |
| - [(= e# a#) |
208 |
| - (when (and (string? e#) (string? a#) (not= e# a#)) |
209 |
| - (let [[_# _# in-both#] (str-diff e# a#)] |
210 |
| - (str-msg e# a# in-both#))) |
211 |
| - (list '~'= '~e '~a) |
212 |
| - (list '~'not= e# a#)]) |
| 214 | + [r# m# ef# af#] (=?-impl {:e '~e :e# e# |
| 215 | + :a '~a :a# a# |
| 216 | + :conform? ~conform?}) |
213 | 217 | humane?# (and humane-test-output? (not (fn? e#)) (not ~conform?))]
|
214 | 218 | (if r#
|
215 | 219 | (t/do-report {:type :pass, :message ~msg,
|
|
218 | 222 | a#)})
|
219 | 223 | (t/do-report
|
220 | 224 | {:type :fail,
|
221 |
| - :message (if m# (if ~msg (str ~msg "\n" m#) m#) ~msg) |
| 225 | + :message (if m# (if-let [msg# ~msg] (str msg# "\n" m#) m#) ~msg) |
222 | 226 | :diffs (if humane?#
|
223 | 227 | [[a# (take 2 (data/diff e# a#))]]
|
224 | 228 | [])
|
|
303 | 307 | (let [within (if (and (sequential? e')
|
304 | 308 | (symbol? (first e'))
|
305 | 309 | (= "expect" (name (first e'))))
|
306 |
| - `(pr-str '~e') |
307 |
| - `(pr-str (list '~'expect '~e' '~a))) |
| 310 | + (pr-str e') |
| 311 | + (pr-str (list 'expect e' a))) |
308 | 312 | msg' `(str/join
|
309 | 313 | "\n"
|
310 | 314 | (cond-> []
|
|
313 | 317 | ~(not= e e')
|
314 | 318 | (conj (str " within: " ~within))
|
315 | 319 | :else
|
316 |
| - (conj (str (pr-str '~a) "\n"))))] |
| 320 | + (conj ~(str (pr-str a) "\n"))))] |
317 | 321 | (cond
|
318 | 322 | (and (sequential? a)
|
319 | 323 | (symbol? (first a))
|
|
0 commit comments