Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Diff for maps #53

Merged
merged 1 commit into from
Oct 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/speclj/should_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
;<-cljs-ignore

)


(context "two collections"
(it "passes if target contains all items"
Expand Down Expand Up @@ -183,6 +184,11 @@
(let [message (str "Expected contents: [1 1 1 5]" endl " got: #{1 5}" endl " missing: [1 1]" endl " extra: []")]
(should= message (failure-message (should== [1 1 1 5] #{1 5})))))

(it "checks equality of maps"
(should-pass! (should== {:a 1} {:a 1}))
(should-fail! (should== {:a 1} {:a 1 :b 2}))
(should= (str "Expected contents: {:a 1}" endl " got: {:a 1, :b 2}" endl " missing: nil" endl " extra: {:b 2}") (failure-message (should== {:a 1} {:a 1 :b 2}))))

))

(context "should-not=="
Expand Down
19 changes: 11 additions & 8 deletions src/speclj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[speclj.config]
[speclj.platform]
[speclj.run.standard])
(:use clojure.data)
;<-cljs-ignore
)

Expand Down Expand Up @@ -259,14 +260,16 @@
(recur (rest coll#) (conj seen# f#)))))))

(defmacro -coll-difference [coll1 coll2]
`(loop [match-with# ~coll1 match-against# ~coll2 diff# []]
(if (empty? match-with#)
diff#
(let [f# (first match-with#)
r# (rest match-with#)]
(if (some #(= % f#) match-against#)
(recur r# (-remove-first match-against# f#) diff#)
(recur r# match-against# (conj diff# f#)))))))
`(if (map? ~coll1)
(first (diff ~coll1 ~coll2))
(loop [match-with# ~coll1 match-against# ~coll2 diff# []]
(if (empty? match-with#)
diff#
(let [f# (first match-with#)
r# (rest match-with#)]
(if (some #(= % f#) match-against#)
(recur r# (-remove-first match-against# f#) diff#)
(recur r# match-against# (conj diff# f#))))))))

(defmacro -difference-message [expected actual extra missing]
`(str
Expand Down