Skip to content

Commit

Permalink
Merge pull request #53 from edtsech/diff-map
Browse files Browse the repository at this point in the history
Diff for maps
  • Loading branch information
slagyr committed Oct 30, 2013
2 parents 86a56d1 + f18b9c2 commit bd56ce4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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 @@ -261,14 +262,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

0 comments on commit bd56ce4

Please # to comment.