From 5a6d3fe6302e5dd5719b9532bcb18e6dbbeecd18 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Mon, 1 Jun 2015 14:21:31 -0400 Subject: [PATCH] fix composing together something defined with comp-paths with other selectors in a comp-unoptimal setting --- src/clj/com/rpl/specter/impl.clj | 4 ++-- test/clj/com/rpl/specter/core_test.clj | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/clj/com/rpl/specter/impl.clj b/src/clj/com/rpl/specter/impl.clj index a4c8db5..095cd1c 100644 --- a/src/clj/com/rpl/specter/impl.clj +++ b/src/clj/com/rpl/specter/impl.clj @@ -210,7 +210,7 @@ (cond (structure-path? this) (coerce-structure-path-direct this) (obj-extends? Collector this) (coerce-collector this) (obj-extends? StructureValsPath this) (coerce-structure-vals-path this) - (instance? TransformFunctions this) this + (instance? TransformFunctions this) (coerce-structure-vals this) :else (throw-illegal (no-prot-error-str this)) )) @@ -220,7 +220,7 @@ (defn comp-unoptimal [sp] (if (instance? java.util.List sp) (->> sp - (map (fn [p] (-> p coerce-structure-vals-direct))) + (map coerce-structure-vals-direct) combine-same-types) (coerce-path sp))) diff --git a/test/clj/com/rpl/specter/core_test.clj b/test/clj/com/rpl/specter/core_test.clj index 68caa10..5c4aaa5 100644 --- a/test/clj/com/rpl/specter/core_test.clj +++ b/test/clj/com/rpl/specter/core_test.clj @@ -271,3 +271,27 @@ (update (comp-paths kw nil) inc m) (update (comp-paths nil kw nil) inc m) )))) + +(deftest compose-empty-comp-path-test + (let [m {:a 1}] + (is (= [1] + (select [:a (comp-paths)] m) + (select [(comp-paths) :a] m) + )))) + +(defspec mixed-selector-test + (for-all+ + [k1 (max-size 3 gen/keyword) + k2 (max-size 3 gen/keyword) + m (max-size 5 + (gen-map-with-keys + gen/keyword + (gen-map-with-keys gen/keyword gen/int k2) + k1))] + (= [(-> m k1 k2)] + (select [k1 (comp-paths k2)] m) + (select [(comp-paths k1) k2] m) + (select [(comp-paths k1 k2) nil] m) + (select [(comp-paths) k1 k2] m) + (select [k1 (comp-paths) k2] m) + )))