From ba908284b912874c7c0bfb3e8086d70e9b359803 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Thu, 16 Jun 2016 09:52:41 -0400 Subject: [PATCH] tests for multi-path and if-path with vals collection --- test/com/rpl/specter/core_test.cljx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index dd99017..cc485b2 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -1268,3 +1268,30 @@ (= (reduce + i (traverse [s/ALL p] v)) (reduce + i (filter p v))) ))) + +(declarepath KeyAccumWalker [k]) +(providepath KeyAccumWalker + (s/if-path + s/must s/STAY + [s/ALL (s/collect-one s/FIRST) s/LAST (s/params-reset KeyAccumWalker)])) + + +(deftest recursive-if-path-select-vals-test + (let [data {"e1" {"e2" {"e1" {:template 1} "e2" {:template 2}}}}] + (is (= [["e1" "e2" "e1" {:template 1}] ["e1" "e2" "e2" {:template 2}]] + (select (KeyAccumWalker :template) data))) + (is (= {"e1" {"e2" {"e1" "e1e2e1" "e2" "e1e2e2"}}} + (transform (KeyAccumWalker :template) + (fn [& all] (apply str (butlast all))) + data))) + )) + +(deftest multi-path-vals-test + (is (= {:a 1 :b 6 :c 3} + (transform [(s/multi-path (s/collect-one :a) (s/collect-one :c)) :b] + + + {:a 1 :b 2 :c 3}))) + (is (= [[1 2] [3 2]] + (select [(s/multi-path (s/collect-one :a) (s/collect-one :c)) :b] + {:a 1 :b 2 :c 3}))) + )