diff --git a/deps.edn b/deps.edn index e620e1d2..4e2ef2a9 100644 --- a/deps.edn +++ b/deps.edn @@ -44,7 +44,7 @@ org.clojure/core.match {:mvn/version "1.0.0"} hiccup/hiccup {:mvn/version "2.0.0-RC1"} rewrite-clj/rewrite-clj {:mvn/version "1.1.46"} - selmer/selmer {:mvn/version "1.12.50"} + selmer/selmer {:mvn/version "1.12.59"} com.taoensso/timbre {:mvn/version "6.0.1"} org.clojure/tools.logging {:mvn/version "1.1.0"} org.clojure/data.priority-map {:mvn/version "1.1.0"} @@ -67,7 +67,7 @@ {:extra-paths ["process/src" "process/test" "test-resources/lib_tests"] :extra-deps {org.clj-commons/clj-http-lite {:mvn/version "0.4.392"} #_#_org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha" - :sha "0dec1f88cbde74a0470b454396f09a03adb4ae39"} + :sha "0dec1f88cbde74a0470b454396f09a03adb4ae39"} lambdaisland/regal {:mvn/version "0.0.143"} cprop/cprop {:mvn/version "0.1.16"} comb/comb {:mvn/version "0.1.1"} diff --git a/project.clj b/project.clj index 70d7f140..79fc7584 100644 --- a/project.clj +++ b/project.clj @@ -72,7 +72,7 @@ :feature/test-check {:source-paths ["feature-test-check"]} :feature/spec-alpha {:source-paths ["feature-spec-alpha"]} :feature/selmer {:source-paths ["feature-selmer"] - :dependencies [[selmer/selmer "1.12.50"]]} + :dependencies [[selmer/selmer "1.12.59"]]} :feature/logging {:source-paths ["feature-logging"] :dependencies [[com.taoensso/timbre "6.0.4"] [org.clojure/tools.logging "1.1.0"]]} diff --git a/test-resources/lib_tests/selmer/core_test.clj b/test-resources/lib_tests/selmer/core_test.clj index 0e200953..72b55012 100644 --- a/test-resources/lib_tests/selmer/core_test.clj +++ b/test-resources/lib_tests/selmer/core_test.clj @@ -8,7 +8,8 @@ [selmer.filters :as f] [selmer.parser :as p :refer [render render-file render-template parse parse-input known-variables - << resolve-var-from-kw env-map]] + << resolve-var-from-kw env-map + resolve-arg]] [selmer.tags :as tags] [clojure.set :as set]) (:import (java.io StringReader ByteArrayInputStream) @@ -1294,3 +1295,32 @@ (is (= "false" (let [y false] (<< "{{y}}"))) "<< picks up local values even if they are false")) + +(deftest resolve-arg-test + (is (= "John" + (resolve-arg "{{variable}}" {:variable "John"})) + "When arg is a variable, returns it substituted by its value.") + (is (= "Hello John!" + (resolve-arg "Hello {{variable}}!" {:variable "John"})) + "When arg contains a variable, return it with the variable substituted by its value.") + (is (= "JOHN" + (resolve-arg "{{variable|upper}}" {:variable "John"})) + "When arg is a filter, returns it where the filter was applied to its value.") + (is (= "Hello JOHN!" + (resolve-arg "Hello {{variable|upper}}!" {:variable "John"})) + "When arg contains a filter, returns it where the filter was applied to its value.") + (is (= "Mr John" + (resolve-arg "{% if variable = \"John\" %}Mr {{variable}}{% endif %}" {:variable "John"})) + "When arg is a tag, returns it where the tag was rendered to its value.") + (is (= "Hello Mr John!" + (resolve-arg "Hello {% if variable = \"John\" %}Mr {{variable}}{% endif %}!" {:variable "John"})) + "When arg contains a tag, returns it where the tag was rendered to its value.") + (is (= "Hello John!" + (resolve-arg "\"Hello John!\"" {})) + "When arg is a double quoted literal string, returns it without double quoting.") + (is (= "Hello John!" + (resolve-arg "Hello John!" {})) + "When arg is a literal string, returns it as is.") + (is (= "29.99" + (resolve-arg "29.99" {})) + "When arg is a literal number, returns it as is."))