From 70523ac38f101f37aa7672293368e68ff68ca59f Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Sun, 24 Apr 2016 11:03:52 -0400 Subject: [PATCH] add zipper tests --- src/clj/com/rpl/specter/zipper.cljx | 4 +- test/com/rpl/specter/cljs_test_runner.cljs | 1 + test/com/rpl/specter/zipper_test.cljx | 66 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/com/rpl/specter/zipper_test.cljx diff --git a/src/clj/com/rpl/specter/zipper.cljx b/src/clj/com/rpl/specter/zipper.cljx index 0f1b7f6..353a3a8 100644 --- a/src/clj/com/rpl/specter/zipper.cljx +++ b/src/clj/com/rpl/specter/zipper.cljx @@ -1,9 +1,9 @@ (ns com.rpl.specter.zipper #+cljs (:require-macros [com.rpl.specter.macros - :refer [fixed-pathed-path defpath]]) + :refer [defpath]]) (:use - #+clj [com.rpl.specter.macros :only [fixed-pathed-path defpath]] + #+clj [com.rpl.specter.macros :only [defpath]] [com.rpl specter]) (:require [clojure [zip :as zip]])) diff --git a/test/com/rpl/specter/cljs_test_runner.cljs b/test/com/rpl/specter/cljs_test_runner.cljs index 122b3f6..5f80a2d 100644 --- a/test/com/rpl/specter/cljs_test_runner.cljs +++ b/test/com/rpl/specter/cljs_test_runner.cljs @@ -3,3 +3,4 @@ [com.rpl.specter.core-test])) (run-tests 'com.rpl.specter.core-test) +(run-tests 'com.rpl.specter.zipper-test) diff --git a/test/com/rpl/specter/zipper_test.cljx b/test/com/rpl/specter/zipper_test.cljx new file mode 100644 index 0000000..ae5f6e0 --- /dev/null +++ b/test/com/rpl/specter/zipper_test.cljx @@ -0,0 +1,66 @@ +(ns com.rpl.specter.zipper-test + #+cljs (:require-macros + [cljs.test :refer [is deftest]] + [cljs.test.check.cljs-test :refer [defspec]] + [com.rpl.specter.cljs-test-helpers :refer [for-all+]] + ) + (:use + #+clj [clojure.test :only [deftest is]] + #+clj [clojure.test.check.clojure-test :only [defspec]] + #+clj [com.rpl.specter.test-helpers :only [for-all+]] + ) + (:require #+clj [clojure.test.check.generators :as gen] + #+clj [clojure.test.check.properties :as prop] + #+cljs [cljs.test.check :as tc] + #+cljs [cljs.test.check.generators :as gen] + #+cljs [cljs.test.check.properties :as prop :include-macros true] + [com.rpl.specter :as s] + [com.rpl.specter.zipper :as z])) + +(defspec zipper-end-equivalency-test + (for-all+ + [v (gen/not-empty (gen/vector gen/int)) + i (gen/vector gen/int)] + (= (s/setval s/END i v) + (s/setval [z/VECTOR-ZIP z/DOWN z/RIGHTMOST z/INNER-RIGHT] i v)) + )) + +(deftest zipper-multi-insert-test + (is (= [1 2 :a :b 3 :a :b 4] + (s/setval [z/VECTOR-ZIP + z/DOWN + z/RIGHT + z/RIGHT + (s/multi-path z/INNER-RIGHT z/INNER-LEFT) + ] + [:a :b] + [1 2 3 4] + ) + (s/setval [z/VECTOR-ZIP + z/DOWN + z/RIGHT + z/RIGHT + (s/multi-path z/INNER-LEFT z/INNER-RIGHT) + ] + [:a :b] + [1 2 3 4] + ) + )) + ) + +(deftest zipper-down-up-test + (is (= [1 [2 3 5] 6] + (s/transform [z/VECTOR-ZIP + z/DOWN + z/RIGHT + z/DOWN + z/RIGHT + z/RIGHT + (s/multi-path + s/STAY + [z/UP z/RIGHT]) + z/NODE] + inc + [1 [2 3 4] 5] + ))) + )