Browse files

Beginning to move `expect` expansion into parsing/

  • Loading branch information...
1 parent b64b774 commit 127ebe48b6928434fbcfaba5439e3d23aadd534b @marick committed Jan 25, 2013
Showing with 57 additions and 25 deletions.
  1. +55 −0 src/midje/parsing/2_to_lexical_maps/examples.clj
  2. +2 −25 src/midje/semi_sweet.clj
View
55 src/midje/parsing/2_to_lexical_maps/examples.clj
@@ -0,0 +1,55 @@
+(ns ^{:doc "generate a map for a particular example"}
+ midje.parsing.2-to-lexical-maps.examples
+ (:use [utilize.seq :only (separate find-first)]
+ [midje.util.object-utils :only [object-name]]
+ [midje.checkers :only [exactly]]
+ [midje.checking.checkers.defining :only [checker? checker-makers]]
+ [midje.parsing.1-to-normal-form.expects :only [expect? up-to-full-expect-form]]
+ [midje.util.form-utils :only [first-named? translate-zipper map-difference
+ hash-map-duplicates-ok pred-cond
+ quoted-list-form? extended-fn?
+ def-many-methods]]
+ [midje.checking.extended-equality :only [extended-= extended-list-=]]
+ [midje.parsing.util.file-position :only [user-file-position]]
+ [midje.util.thread-safe-var-nesting :only [namespace-values-inside-out
+ with-pushed-namespace-values
+ with-altered-roots]]
+ [midje.parsing.util.wrapping :only [with-wrapping-target]]
+ [midje.util.deprecation :only [deprecate]]
+ [clojure.algo.monads :only [defmonad domonad]]
+ [midje.parsing.arrow-symbols]
+ midje.error-handling.validation-errors
+ midje.error-handling.semi-sweet-validations
+ [clojure.tools.macro :only [macrolet]])
+ (:require [midje.data.metaconstant :as metaconstant]
+ [midje.data.nested-facts :as nested-facts]
+ [clojure.zip :as zip]
+ [midje.config :as config]
+ [midje.parsing.util.fnref :as fnref]
+ [midje.error-handling.exceptions :as exceptions]
+ [midje.parsing.lexical-maps :as lexical-maps]
+ [midje.emission.api :as emit])
+ (:import midje.data.metaconstant.Metaconstant))
+
+(defmulti expect-expansion (fn [_call-form_ arrow & _rhs_]
+ (name arrow)))
+
+(def-many-methods expect-expansion [=> =not=> =deny=>]
+ [call-form arrow expected-result fakes overrides]
+ `(let [check# (lexical-maps/example ~call-form ~arrow ~expected-result ~overrides)]
+ (midje.checking.examples/check-one check# ~fakes)))
+
+(defmethod expect-expansion =expands-to=>
+ [call-form _arrow_ expected-result fakes overrides]
+ (let [expanded-macro `(macroexpand-1 '~call-form)
+ escaped-expected-result `(quote ~expected-result)]
+ `(let [check# (lexical-maps/example ~expanded-macro => ~escaped-expected-result
+ ~(concat overrides [:expected-result-form escaped-expected-result]))]
+ (midje.checking.examples/check-one check# ~fakes))))
+
+(defmethod expect-expansion =future=>
+ [call-form arrow expected-result _fakes_ overrides]
+ `(let [check# (lexical-maps/example ~call-form ~arrow ~expected-result ~overrides)]
+ (emit/future-fact (nested-facts/descriptions ~(str "on `" call-form "`"))
+ (:position check#))))
+
View
27 src/midje/semi_sweet.clj
@@ -19,36 +19,13 @@
[midje.emission.api :as emit]
midje.checking.examples
[midje.parsing.util.fnref :as fnref]
+ [midje.parsing.2-to-lexical-maps.examples :as parse-examples]
[midje.parsing.2-to-lexical-maps.fakes :as parse-fakes]
[midje.parsing.2-to-lexical-maps.data-fakes :as parse-data-fakes]))
(immigrate 'midje.parsing.arrow-symbols)
-;;; Conversions to unprocessed form
-
-
-(defmulti ^{:private true} expect-expansion (fn [_call-form_ arrow & _rhs_]
- (name arrow)))
-
-(def-many-methods expect-expansion [=> =not=> =deny=>]
- [call-form arrow expected-result fakes overrides]
- `(let [check# (lexical-maps/example ~call-form ~arrow ~expected-result ~overrides)]
- (midje.checking.examples/check-one check# ~fakes)))
-
-(defmethod expect-expansion =expands-to=>
- [call-form _arrow_ expected-result fakes overrides]
- (let [expanded-macro `(macroexpand-1 '~call-form)
- escaped-expected-result `(quote ~expected-result)]
- `(let [check# (lexical-maps/example ~expanded-macro => ~escaped-expected-result
- ~(concat overrides [:expected-result-form escaped-expected-result]))]
- (midje.checking.examples/check-one check# ~fakes))))
-
-(defmethod expect-expansion =future=>
- [call-form arrow expected-result _fakes_ overrides]
- `(let [check# (lexical-maps/example ~call-form ~arrow ~expected-result ~overrides)]
- (emit/future-fact (nested-facts/descriptions ~(str "on `" call-form "`"))
- (:position check#))))
;;; Interface: unfinished
@@ -122,7 +99,7 @@
(domonad validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
[fakes overrides] (separate-by a-fake? fakes+overrides)
_ (validate fakes)]
- (expect-expansion call-form arrow expected-result fakes overrides))))
+ (parse-examples/expect-expansion call-form arrow expected-result fakes overrides))))
(defmacro not-called

0 comments on commit 127ebe4

Please sign in to comment.