Skip to content
Browse files

[Issue #76] removed use of core.match

  • Loading branch information...
1 parent a6de0a3 commit 51a23deca9cd00909d037fb4b8dde0b30de26be3 @AlexBaranosky AlexBaranosky committed Apr 25, 2012
View
3 project.clj
@@ -6,8 +6,7 @@
[colorize "0.1.1"]
[org.clojure/tools.macro "0.1.1"]
[org.clojure/core.incubator "0.1.0"]
- [swiss-arrows "0.1.0"]
- [org.clojure/core.match "0.2.0-alpha9"]])
+ [swiss-arrows "0.1.0"]])
(defproject midje "1.4.0-SNAPSHOT"
:description "A TDD library for Clojure that supports top-down ('mockish') TDD, encourages readable tests, provides a smooth migration path from clojure.test, balances abstraction and concreteness, and strives for graciousness."
View
24 src/midje/checkers/collection.clj
@@ -4,7 +4,6 @@
midje.checkers.collection
(:use [clojure.set :only [union]]
[clojure.pprint :only [cl-format]]
- [clojure.core.match :only [match]]
[midje.util.backwards-compatible-utils :only [every-pred-m]]
[midje.util.form-utils :only [regex? record? classic-map? pred-cond macro-for]]
[midje.checkers collection-util util extended-equality extended-falsehood chatty defining collection-comparison]
@@ -66,17 +65,18 @@
;;Reduce arguments to standard forms so there are fewer combinations to
;;consider. Also blow up for some incompatible forms."
[actual expected looseness]
- (compatibility-check actual expected looseness)
- (match [actual expected]
- [(a :when sequential?) (e :when set?)] [actual (vec expected) (union looseness #{:in-any-order })]
- [(a :when sequential?) (e :when right-hand-singleton?)] [actual [expected] (union looseness #{:in-any-order })]
- [(a :when sequential?) _] [actual expected looseness]
- [(a :when map?) (b :when map?)] [actual expected looseness]
- [(a :when map?) _] [actual (into {} expected) looseness]
- [(a :when set?) _] (recur (vec actual) expected looseness-modifiers)
- [(a :when string?) (e :when [(complement string?)
- (complement regex?)])] (recur (vec actual) expected looseness-modifiers)
- :else [actual expected looseness]))
+ (compatibility-check actual expected looseness)
+ (cond
+ (and (sequential? actual) (set? expected)) [actual (vec expected) (union looseness #{:in-any-order })]
+ (and (sequential? actual) (right-hand-singleton? expected)) [actual [expected] (union looseness #{:in-any-order })]
+ (sequential? actual) [actual expected looseness]
+ (and (map? actual) (map? expected)) [actual expected looseness]
+ (map? actual) [actual (into {} expected) looseness]
+ (set? actual) (recur (vec actual) expected looseness-modifiers)
+ (and (string? actual)
+ (not (string? expected))
+ (not (regex? expected))) (recur (vec actual) expected looseness-modifiers)
+ :else [actual expected looseness]))
(match? [actual expected looseness]
(let [comparison (compare-results actual expected looseness)]
View
21 src/midje/checkers/extended_equality.clj
@@ -1,7 +1,6 @@
(ns ^{:doc "`=` extended for regular expressions, functions, etc."}
midje.checkers.extended-equality
- (:use [clojure.core.match :only [match]]
- [midje.checkers.extended-falsehood :only [data-laden-falsehood?]]
+ (:use [midje.checkers.extended-falsehood :only [data-laden-falsehood?]]
[midje.util.form-utils :only [classic-map? extended-fn? pairs record? regex?]]))
(defn extended-= [actual expected]
@@ -10,15 +9,15 @@
(if (data-laden-falsehood? function-result)
false
function-result)))]
- (try
- (match [actual expected]
- [(a :when data-laden-falsehood?) _] actual
- [_ (e :when data-laden-falsehood?)] expected
- [_ (e :when extended-fn?)] (evaluate-extended-fn)
- [(a :when regex?) (e :when regex?)] (= (str actual) (str expected))
- [_ (e :when regex?)] (re-find expected actual)
- [(a :when record?) (e :when classic-map?)] (= (into {} actual) expected)
- :else (= actual expected))
+ (try
+ (cond
+ (data-laden-falsehood? actual) actual
+ (data-laden-falsehood? expected) expected
+ (extended-fn? expected) (evaluate-extended-fn)
+ (every? regex? [actual expected]) (= (str actual) (str expected))
+ (regex? expected) (re-find expected actual)
+ (and (record? actual) (classic-map? expected)) (= (into {} actual) expected)
+ :else (= actual expected))
(catch Throwable ex false))))
(defn extended-list-=
View
21 src/midje/ideas/reporting/string_format.clj
@@ -4,7 +4,6 @@
[midje.util.object-utils :only [function-name function-name-or-spewage named-function?]]
midje.error-handling.exceptions
[midje.internal-ideas.fact-context :only [format-nested-descriptions]]
- [clojure.core.match :only [match]]
[midje.util.form-utils :only [pred-cond]])
(:require [midje.util.colorize :as color]))
@@ -83,12 +82,20 @@
(str " " (pr-str (:actual m)))))
(defmethod report-strings :mock-incorrect-call-count [m]
- (letfn [(format-one-failure [fail]
- (let [msg (match [(:expected-count fail) (:actual-count fail)]
- [nil 0] "[expected at least once, actually never called]"
- [nil act] (cl-format nil "[expected at least once, actually called ~R time~:P]" act)
- [exp act] (cl-format nil "[expected :times ~A, actually called ~R time~:P]" exp act))]
- (str " " (:expected fail) " " msg)))]
+ (letfn [
+ (format-one-failure [fail]
+ (let [exp (:expected-count fail)
+ act (:actual-count fail)
+ msg (cond
+ (and (nil? exp) (zero? act))
+ "[expected at least once, actually never called]"
+
+ (nil? exp)
+ (cl-format nil "[expected at least once, actually called ~R time~:P]" act)
+
+ :else
+ (cl-format nil "[expected :times ~A, actually called ~R time~:P]" exp act))]
+ (str " " (:expected fail) " " msg)))]
(concat
(list (fail-at (first (:failures m)))
View
25 src/midje/util/form_utils.clj
@@ -1,23 +1,11 @@
(ns ^{:doc "Utility functions dealing with checking or tranforming forms."}
midje.util.form-utils
(:use [midje.util.treelike :only [tree-variant]]
- [clojure.core.match :only [match]]
+ [midje.util.backwards-compatible-utils :only [every-pred-m]]
[clojure.set :only [difference]]
[utilize.seq :only (first-truthy-fn)])
(:require [clojure.zip :as zip]))
-
-(defn single-destructuring-arg->form+name [arg-form]
- (let [as-symbol (gensym 'symbol-for-destructured-arg)
- snd-to-last-is-as? #(= :as (second (reverse %)))
- has-key-as? #(contains? % :as)]
- (match [arg-form]
- [(v :when [vector? snd-to-last-is-as?])] [v (last v)]
- [(v :when [vector?])] [(-> v (conj :as) (conj as-symbol)) as-symbol]
- [(m :when [map? has-key-as?])] [m (:as m)]
- [(m :when [map?])] [(assoc m :as as-symbol) as-symbol]
- :else [arg-form arg-form] )))
-
(defn regex? [x]
(= (class x) java.util.regex.Pattern))
@@ -145,6 +133,17 @@
~result
(pred-cond ~item ~@preds+results))))
+(defn single-destructuring-arg->form+name [arg-form]
+ (let [as-symbol (gensym 'symbol-for-destructured-arg)
+ snd-to-last-is-as? #(= :as (second (reverse %)))
+ has-key-as? #(contains? % :as)]
+ (pred-cond arg-form
+ (every-pred-m vector? snd-to-last-is-as?) [arg-form (last arg-form)]
+ vector? [(-> arg-form (conj :as) (conj as-symbol)) as-symbol]
+ (every-pred-m map? has-key-as?) [arg-form (:as arg-form)]
+ map? [(assoc arg-form :as as-symbol) as-symbol]
+ :else [arg-form arg-form] )))
+
(defmacro macro-for
"Macroexpands the body once for each of the elements in the
right-side argument of the bindings, which should be a seq"

0 comments on commit 51a23de

Please sign in to comment.
Something went wrong with that request. Please try again.