Skip to content

Commit

Permalink
cleanup in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Dec 29, 2010
1 parent 346fde8 commit 0d71d9e
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/midje/util/checkers.clj
Expand Up @@ -343,32 +343,30 @@

;;

(defn compatibility-check [actual expected kind]
(defn compatibility-failure [actual expected kind]
(cond (regex? expected)
(cond (and (not (sequential? actual))
(not (empty? kind)))
(throw (Error. (str "I don't know how to make sense of a "
"regular expression applied "
kind "."))))
(and (not (sequential? actual))
(not (empty? kind))
(noted-falsehood (str "I don't know how to make sense of a "
"regular expression applied "
kind ".")))

(not (collection-like? actual))
(throw (Error. (str "You can't compare " (pr-str actual) " (" (type actual)
") to " (pr-str expected) " (" (type expected) ").")))
(noted-falsehood (format "You can't compare %s (%s) to %s (%s)."
(pr-str actual) (type actual)
(pr-str expected) (type expected)))

(and (map? actual)
(not (map? expected)))
(try (into {} expected)
(try (into {} expected) nil
(catch Throwable ex
(throw (Error. (str "If " (pr-str actual) " is a map, "
(pr-str expected)
" should look like map entries.")))))))

(format "If %s is a map, %s should look like map entries."
(pr-str actual) (pr-str expected))))))

(defn- standardized-arguments [actual expected kind]
"Reduce arguments to standard forms so there are fewer combinations to
consider. Also blow up for some incompatible forms."
consider."

(compatibility-check actual expected kind)
(cond (sequential? actual)
(cond (set? expected)
[actual (vec expected) (union kind #{:in-any-order})]
Expand Down Expand Up @@ -515,13 +513,16 @@
(fn [actual#]
;; (prn "checking" actual# expected# kind#)
(add-actual actual#
(try (~checker-fn actual# expected# kind#)
(catch Error ex#
(tag-as-chatty-falsehood {
:notes [(.getMessage ex#)]}))))))
merge
{:midje/chatty-checker true, :midje/checker true}))
{:midje/checker true}))
(if (chatty-checker-falsehood?
(compatibility-failure actual# expected# kind#))
(compatibility-failure actual# expected# kind#)
(try (~checker-fn actual# expected# kind#)
(catch Error ex#
(tag-as-chatty-falsehood {
:notes [(.getMessage ex#)]}))))))
merge
{:midje/chatty-checker true, :midje/checker true}))
{:midje/checker true})))

(def contains (container-checker contains
(fn [actual expected kind]
Expand Down

0 comments on commit 0d71d9e

Please sign in to comment.