Skip to content

Commit

Permalink
recursive variable resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
jrincon2 committed Aug 21, 2019
1 parent 2241feb commit 9455549
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/rester/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
[(keyword (str/lower-case key)) (or value true)])))

(defn replace-opts [s opts]
(cond (string? s)
(str/replace s placeholder-pattern
#(str (or (opts (second %) (parse-date-exp (second %)))
(log/error "missing argument:" (second %)) "")))
(cond
(string? s) (str/replace s placeholder-pattern
#(str (or (replace-opts (opts (second %) (parse-date-exp (second %))) opts)
(log/error "missing argument:" (second %)) "")))
(sequential? s) (map #(replace-opts % opts) s)
:else s))

Expand Down
17 changes: 6 additions & 11 deletions test/rester/utils_test.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
(ns rester.utils-test
(:require [clojure.test :refer :all]
[rester.utils
:refer
[find-cycle
like
load-tests-from
parse-date-exp
parse-options
process-tests
rows->test-cases
str->map
to-test-case]])
[rester.utils :refer :all])
(:import clojure.lang.ExceptionInfo
java.text.SimpleDateFormat
java.util.Date))
Expand Down Expand Up @@ -86,3 +76,8 @@
{:keys[runnable ignored skipped]} (process-tests ts {})]
(is (= 4 (count ts)))
(is (= 4 (count runnable))))))

(deftest test-variable-expansion
(testing "expanding vars"
(is (= "var is 42" (replace-opts "var is $x$" {"x" 42})))
(is (= "answer to what's life? is 42" (replace-opts "answer to $question$" {"question" "what's life? is $life$" "life" 42})))))

0 comments on commit 9455549

Please sign in to comment.