1. Meikel Brandmeyer
  2. ClojureCheck


ClojureCheck / src / main / clojure / clojurecheck / core.clj

Diff from to

File src/main/clojure/clojurecheck/core.clj

 (declare transform)
+(defn #^{:private true} quote-fn
+  [x]
+  `(quote ~x))
 (defmacro generators
   "Takes a map of locals to generators. Upon generation of a value, binds
   the generated values to the locals and executes body to obtain the final
   {:added "2.1"}
   [bindings & body]
   (let [ks  (keys bindings)
-        gen (zipmap (map (fn [k] `(quote ~k)) ks) (vals bindings))]
+        gen (zipmap (map quote-fn ks) (vals bindings))]
     `(transform ~gen (fn [{:syms [~@ks]}] ~@body))))
 ;; ## Data structure generators
   (let [f (if (fn? f) f (constantly f))]
     (reify Generator (arbitrary [this size] (arbitrary gen (f size))))))
+;; # `clojure.test` interface
 (defn *size-scale*
   "The scale function used to scale up the size guidance with increasing
   trials while testing a property with generated input."
           (recur (inc n)))))))
 (defmacro property
-  "Defines a property consisting of a binding vector as for let-gen
+  "Defines a property consisting of a binding map as for `generators`
   which associates locals with the given generators. When testing the
   property the locals will be assigned the values generated.
   The body is a normal deftest body."
   {:added "2.0"}
   [msg bindings & body]
-  (let [locals (remove keyword? (take-nth 2 bindings))]
+  (let [locals  (keys bindings)
+        qlocals (map quote-fn locals)
+        gen     (zipmap qlocals (vals bindings))]
     `(property* ~msg
-                (quote ~locals)
-                (let-gen ~bindings [~@locals])
-                (fn [[~@locals]] ~@body))))
+                [~@qlocals]
+                ~gen
+                (fn [{:syms [~@locals]}] ~@body))))
 (defmethod report ::property-fail
   [{:keys [message locals input attempts failures] :as this}]