Skip to content

Commit

Permalink
Filtering out generated symbols
Browse files Browse the repository at this point in the history
When trying to generate code to destructure the results of generators
with for-all, the macro was getting caught up by gen-syms. By filtering
out symbols with the prefixes "map__" and "vec__", the macro no longer
tries to generate code that references the generated symbols and works
as expected (or at least how I expected it to work). A simple test was
added as well.
  • Loading branch information
Zack Maril committed Feb 17, 2015
1 parent e618e1e commit ef499a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/com/gfredericks/test/chuck/properties.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
;; property
;;

(defn ^:private probably-gen-sym? [sym]
(let [s (name sym)]
(or (.startsWith s "vec__")
(.startsWith s "map__"))))

(defn ^:private for-bindings-in-binding-expr
[expr]
;; this'll get gensyms o_O
(->> (clojure.core/destructure [expr :dummy])
(partition 2)
(map first)))
(map first)
(filter (complement probably-gen-sym?))))

(defn ^:private for-bindings-in-clause
[left right]
Expand Down
5 changes: 5 additions & 0 deletions test/com/gfredericks/test/chuck/properties_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [clojure.test :refer :all]
[clojure.test.check :as t.c]
[clojure.test.check.generators :as gen]
[clojure.test.check.clojure-test :refer [defspec]]
[com.gfredericks.test.chuck.properties :as prop']))

(deftest it-handles-exceptions-correctly
Expand All @@ -19,3 +20,7 @@
(let [[m] fail]
(is (= ['x] (keys m)))
(is (<= 0 (get m 'x) 10)))))

(defspec for-all-destructured-args-work-correctly 10
(prop'/for-all [[a b] (gen/tuple gen/int gen/int)]
(+ a b)))

0 comments on commit ef499a7

Please sign in to comment.