Skip to content

Commit eda6145

Browse files
committed
fixes #23
1 parent 5bf2b9d commit eda6145

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Only accretive/fixative changes will be made from now on.
88

99
* 2.0.next in progress
10+
* Fix #23 by adding support for set-`in`-set expectations.
1011
* Documentation updates.
1112
* Build deps updates.
1213

deps.edn

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:aliases
55
{;; for help: clojure -A:deps -T:build help/doc
66
:build {:deps {io.github.seancorfield/build-clj
7-
{:git/tag "v0.5.5" :git/sha "0527130"}}
7+
{:git/tag "v0.6.0" :git/sha "2451bea"}}
88
:ns-default build}
99

1010
;; versions to test against:

src/expectations/clojure/test.cljc

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; copyright (c) 2018-2020 sean corfield, all rights reserved
1+
;; copyright (c) 2018-2021 sean corfield, all rights reserved
22

33
(ns expectations.clojure.test
44
"This namespace provides compatibility with `clojure.test` and related tooling.
@@ -297,18 +297,23 @@
297297

298298
(and (sequential? a) (= 'in (first a)))
299299
(let [form `(~'expect ~e ~a)]
300-
`(let [a# ~(second a)
300+
`(let [e# ~e
301+
a# ~(second a)
301302
not-in# (str '~e " not found in " a#)
302303
msg# (if (seq ~msg') (str ~msg' "\n" not-in#) not-in#)]
303-
(cond (or (sequential? a#) (set? a#))
304+
(cond (and (set? a#) (set? e#))
305+
;; special case of set in set -- report any elements from
306+
;; expected set that are not in the actual set:
307+
(t/is (~'=? (clojure.set/difference e# a#) #{} '~form) msg#)
308+
(or (sequential? a#) (set? a#))
304309
(let [all-reports# (atom nil)
305310
one-report# (atom nil)]
306311
;; we accumulate any and all failures and errors but we
307312
;; only accumulate passes if each sequential expectation
308313
;; fully passes (i.e., no failures or errors)
309314
(with-redefs [t/do-report (all-report one-report#)]
310315
(doseq [a'# a#]
311-
(expect ~e a'# msg# ~ex? ~form)
316+
(expect e# a'# msg# ~ex? ~form)
312317
(if (or (contains? @one-report# :error)
313318
(contains? @one-report# :fail))
314319
(do
@@ -332,17 +337,16 @@
332337
(when-let [r# (first (:fail @all-reports#))]
333338
(t/do-report r#)))))
334339
(map? a#)
335-
(let [e# ~e]
336-
(if (map? e#)
337-
(let [submap# (select-keys a# (keys e#))]
338-
(t/is (~'=? e# submap# '~form) ~msg'))
339-
(throw (#?(:clj IllegalArgumentException.
340-
:cljs js/Error.)
341-
"'in' requires map or sequence"))))
340+
(if (map? e#)
341+
(let [submap# (select-keys a# (keys e#))]
342+
(t/is (~'=? e# submap# '~form) ~msg'))
343+
(throw (#?(:clj IllegalArgumentException.
344+
:cljs js/Error.)
345+
"'in' requires map or sequence")))
342346
:else
343347
(throw (#?(:clj IllegalArgumentException.
344348
:cljs js/Error.)
345-
"'in' requires map or sequence")))))
349+
"'in' requires map or sequence")))))
346350

347351
(and (sequential? e) (= 'more (first e)))
348352
(let [es (mapv (fn [e] `(expect ~e ~a ~msg ~ex? ~e')) (rest e))]

test/expectations/clojure/test_test.cljc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; copyright (c) 2019-2020 sean corfield, all rights reserved
1+
;; copyright (c) 2019-2021 sean corfield, all rights reserved
22

33
(ns expectations.clojure.test-test
44
"Test the testing framework -- this is sometimes harder than you might think!
@@ -104,6 +104,7 @@
104104

105105
(deftest collection-test
106106
(is (sut/expect {:foo 1} (in {:foo 1 :cat 4})))
107+
(is (sut/expect #{1 2} (in #{0 1 2 3})))
107108
;; TODO: need better tests here
108109
(is (nil? (sut/expect :foo (in #{:foo :bar}))))
109110
(is (nil? (sut/expect :foo (in [:bar :foo])))))

0 commit comments

Comments
 (0)