diff --git a/CHANGES.md b/CHANGES.md index b23a548..919fc36 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ ## 1.0.5-SNAPSHOT -* Add implicit navigator for regexes, which navigate to every match in a string and support replacement with a new substring. +* Add `regex-nav` navigator for regexes, which navigate to every match in a string and support replacement with a new substring. ## 1.0.4 diff --git a/src/clj/com/rpl/specter.cljc b/src/clj/com/rpl/specter.cljc index 5f6e6e4..a24871d 100644 --- a/src/clj/com/rpl/specter.cljc +++ b/src/clj/com/rpl/specter.cljc @@ -1177,10 +1177,6 @@ ImplicitNav (implicit-nav [this] (pred this))) -(extend-type #?(:clj java.util.regex.Pattern :cljs js/RegExp) - ImplicitNav - (implicit-nav [this] (regex-nav this))) - (defnav ^{:doc "Navigates to the provided val if the structure is nil. Otherwise it stays navigated at the structure."} diff --git a/test/com/rpl/specter/core_test.cljc b/test/com/rpl/specter/core_test.cljc index 55029af..6ab8dd6 100644 --- a/test/com/rpl/specter/core_test.cljc +++ b/test/com/rpl/specter/core_test.cljc @@ -1435,17 +1435,17 @@ ) (deftest regex-navigation-test - (is (= (select #"t" "test") ["t" "t"])) - (is (= (select [:a #"t"] {:a "test"}) ["t" "t"])) - (is (= (transform #"t" clojure.string/capitalize "test") "TesT")) - (is (= (transform [:a #"t"] clojure.string/capitalize {:a "test"}) {:a "TesT"})) - (is (= (transform #"\s+\w" clojure.string/triml "Hello World!") "HelloWorld!")) - (is (= (setval #"t" "z" "test") "zesz")) - (is (= (setval [:a #"t"] "z" {:a "test"}) {:a "zesz"})) - (is (= (transform #"aa*" (fn [s] (-> s count str)) "aadt") "2dt")) - (is (= (transform #"[Aa]+" (fn [s] (apply str (take (count s) (repeat "@")))) "Amsterdam Aardvarks") "@msterd@m @@rdv@rks")) - (is (= (select [#"(\S+):\ (\d+)" (s/nthpath 2)] "Mary: 1st George: 2nd Arthur: 3rd") ["1" "2" "3"])) - (is (= (transform (s/subselect #"\d\w+") reverse "Mary: 1st George: 2nd Arthur: 3rd") "Mary: 3rd George: 2nd Arthur: 1st")) + (is (= (select (s/regex-nav #"t") "test") ["t" "t"])) + (is (= (select [:a (s/regex-nav #"t")] {:a "test"}) ["t" "t"])) + (is (= (transform (s/regex-nav #"t") clojure.string/capitalize "test") "TesT")) + (is (= (transform [:a (s/regex-nav #"t")] clojure.string/capitalize {:a "test"}) {:a "TesT"})) + (is (= (transform (s/regex-nav #"\s+\w") clojure.string/triml "Hello World!") "HelloWorld!")) + (is (= (setval (s/regex-nav #"t") "z" "test") "zesz")) + (is (= (setval [:a (s/regex-nav #"t")] "z" {:a "test"}) {:a "zesz"})) + (is (= (transform (s/regex-nav #"aa*") (fn [s] (-> s count str)) "aadt") "2dt")) + (is (= (transform (s/regex-nav #"[Aa]+") (fn [s] (apply str (take (count s) (repeat "@")))) "Amsterdam Aardvarks") "@msterd@m @@rdv@rks")) + (is (= (select [(s/regex-nav #"(\S+):\ (\d+)") (s/nthpath 2)] "Mary: 1st George: 2nd Arthur: 3rd") ["1" "2" "3"])) + (is (= (transform (s/subselect (s/regex-nav #"\d\w+")) reverse "Mary: 1st George: 2nd Arthur: 3rd") "Mary: 3rd George: 2nd Arthur: 1st")) ) (deftest single-value-none-navigators-test