From dab495304ab92287e8958466d570ad62742b69e2 Mon Sep 17 00:00:00 2001 From: Ikuru Kyogoku Date: Fri, 29 Mar 2019 01:55:44 +0900 Subject: [PATCH] Add :duct/regex reader tag --- src/duct/core.clj | 8 +++++--- test/duct/core_test.clj | 15 +++++++++------ test/duct/readers.edn | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/duct/core.clj b/src/duct/core.clj index 8f2f153..71724ed 100644 --- a/src/duct/core.clj +++ b/src/duct/core.clj @@ -11,7 +11,8 @@ [duct.core.resource :as resource] [integrant.core :as ig] [medley.core :as m] - [clojure.walk :as walk])) + [clojure.walk :as walk]) + (:import [java.util.regex Pattern])) (def target-path "A path to place generated files in. Typically used by compilers. Can be set @@ -110,7 +111,8 @@ (merge {'duct/env env/env 'duct/include (make-include readers) - 'duct/resource resource} + 'duct/resource resource + 'duct/regex re-pattern} readers)) (defn read-config @@ -119,7 +121,7 @@ #duct/env : an environment variable, see [[duct.core.env/env]] - + #duct/include : substitute for a configuration on the classpath diff --git a/test/duct/core_test.clj b/test/duct/core_test.clj index 5d58b14..fa8b130 100644 --- a/test/duct/core_test.clj +++ b/test/duct/core_test.clj @@ -48,12 +48,15 @@ {::a {:x 1}} {::a (ig/refset ::b)} {::a (ig/refset ::b)})) (deftest test-read-config - (is (= (core/read-config (io/resource "duct/readers.edn") {'custom/bar (fn [x] {:x x})}) - {:foo/a {:x "bar"} - :foo/b {:bar/a {:x 1}, :bar/b (ig/ref :bar/a) :bar/c {:baz/a {:x 1}}} - :foo/c (core/resource "duct/config.edn") - :foo/d (ig/ref :foo/a) - :foo/e (ig/refset :foo/b)}))) + (let [config (core/read-config (io/resource "duct/readers.edn") {'custom/bar (fn [x] {:x x})})] + (is (= (dissoc config :foo/f) + {:foo/a {:x "bar"} + :foo/b {:bar/a {:x 1}, :bar/b (ig/ref :bar/a) :bar/c {:baz/a {:x 1}}} + :foo/c (core/resource "duct/config.edn") + :foo/d (ig/ref :foo/a) + :foo/e (ig/refset :foo/b)})) + (is (= (.pattern (:foo/f config)) + "baz")))) (defmethod ig/init-key ::foo [_ {:keys [x]}] #(update % ::x (fnil conj []) x)) diff --git a/test/duct/readers.edn b/test/duct/readers.edn index c93fcfb..dc691ee 100644 --- a/test/duct/readers.edn +++ b/test/duct/readers.edn @@ -2,4 +2,5 @@ :foo/b #duct/include "duct/config.edn" :foo/c #duct/resource "duct/config.edn" :foo/d #ig/ref :foo/a - :foo/e #ig/refset :foo/b} + :foo/e #ig/refset :foo/b + :foo/f #duct/regex "baz"}