Permalink
Browse files

Push work over into lexical-maps

  • Loading branch information...
1 parent 72a96a6 commit d4dd21492fb1184915289c2b855fca9d17e7f7f8 @marick committed Jan 25, 2013
Showing with 24 additions and 26 deletions.
  1. +1 −7 src/midje/parsing/2_to_lexical_maps/fakes.clj
  2. +23 −19 src/midje/parsing/lexical_maps.clj
@@ -68,11 +68,5 @@
(let [[_ [fnref & args :as call-form] arrow result & overrides] a-list]
(when (statically-disallowed-prerequisite-function (fnref/fnref-var-object fnref))
(raise-disallowed-prerequisite-error (fnref/fnref-var-object fnref)))
- (let [source-details `{:call-form '~call-form
- :arrow '~arrow
- :rhs '~(cons result overrides)}]
- `(merge
- (lexical-maps/fake ~call-form ~fnref ~args ~arrow ~result)
- ~source-details
- ~(apply hash-map-duplicates-ok overrides))))))
+ (lexical-maps/fake call-form fnref args arrow result overrides))))
@@ -21,7 +21,7 @@
;;; ... to see this:
;;;
-(comment
+(comment ; --------------------------------------------------------
(clojure.core/merge
{:position (midje.parsing.util.file-position/user-file-position),
:expected-result-form '(just a 2),
@@ -33,7 +33,7 @@
(midje.util.form-utils/hash-map-duplicates-ok
:position
(midje.parsing.util.file-position/line-number-known 2)))
-)
+) ; ---------------------------------------------------------------
;;; Example maps
@@ -64,23 +64,27 @@
;; A fake map describes all or part of a temporary rebinding of a var with a function that
;; captures invocations and also returns canned values.
-(defmacro fake [call-form fnref args arrow result]
- ;; The (vec args) keeps something like (...o...) from being
- ;; evaluated as a function call later on. Right approach would
- ;; seem to be '~args. That causes spurious failures. Debug
- ;; someday.
- `{:type :fake
- :var ~(fnref/fnref-call-form fnref)
- :value-at-time-of-faking (if (bound? ~(fnref/fnref-call-form fnref))
- ~(fnref/fnref-dereference-form fnref))
- :arg-matchers (map from-fake-maps/mkfn:arg-matcher ~(vec args))
- :result-supplier (from-fake-maps/mkfn:result-supplier ~arrow ~result)
- :times :default ; Default allows for a more attractive error in the most common case.
-
- :position (position/user-file-position)
- :call-count-atom (atom 0)
- :call-text-for-failures (str '~call-form)})
-
+(defn fake [call-form fnref args arrow result overrides]
+ (let [source-details `{:call-form '~call-form
+ :arrow '~arrow
+ :rhs '~(cons result overrides)}
+ override-map `(hash-map-duplicates-ok ~@overrides)
+ result `(merge
+ {:type :fake
+ :var ~(fnref/fnref-call-form fnref)
+ :value-at-time-of-faking (if (bound? ~(fnref/fnref-call-form fnref))
+ ~(fnref/fnref-dereference-form fnref))
+ :arg-matchers (map from-fake-maps/mkfn:arg-matcher ~(vec args))
+ :result-supplier (from-fake-maps/mkfn:result-supplier ~arrow ~result)
+ :times :default ; Default allows for a more attractive error in the most common case.
+
+ :position (position/user-file-position)
+ :call-count-atom (atom 0)
+ :call-text-for-failures (str '~call-form)}
+ ~source-details
+ ~override-map)]
+ ;; pprint result
+ result))
;;; Metaconstant Detail Maps

0 comments on commit d4dd214

Please sign in to comment.