mirror of https://github.com/status-im/pluto.git
Interpolate nil values to empty string
This commit is contained in:
parent
0f167bbf69
commit
21e48f29d5
|
@ -73,5 +73,5 @@
|
|||
(if (seq v)
|
||||
(apply #?(:clj format-en :cljs gstring/format)
|
||||
(string/replace s placeholder-pattern
|
||||
(fn [[_ pattern]] (format-pattern pattern))) (map values names))
|
||||
(fn [[_ pattern]] (format-pattern pattern))) (map #(or (get values %) "") names))
|
||||
s)})))
|
||||
|
|
|
@ -9,15 +9,16 @@
|
|||
(clojure.core/slurp file)))
|
||||
|
||||
(deftest interpolate
|
||||
#_
|
||||
(is (= {:errors [(error/syntax ::error/invalid-placeholders #{'id1})]}
|
||||
(is (= {:errors [(error/syntax ::error/invalid {:type :placeholders} {:data #{'id}})]}
|
||||
(utils/interpolate nil "test-${id}")))
|
||||
(is (= {:errors [(error/syntax ::error/invalid {:type :placeholders} {:data #{'id1}})]}
|
||||
(utils/interpolate {'id 3} "${id1}")))
|
||||
(is (= {:data "test-"} (utils/interpolate {'id nil} "test-${id}")))
|
||||
(is (= {:data "test-3"} (utils/interpolate {'id 3} "test-${id}")))
|
||||
(is (= {:data "test- 3"} (utils/interpolate {'id "3"} "test-${id:2s}")))
|
||||
(is (= {:data "2.369"} (utils/interpolate {'f 2.369} "${f}")))
|
||||
(is (= {:data "12345"} (utils/interpolate {'d 12345} "${d:2d}")))
|
||||
(is (= {:data " 12345"} (utils/interpolate {'d 12345} "${d:6d}")))
|
||||
(is (= {:data "2.37"} (utils/interpolate {'f 2.369} "${f:1.2f}")))
|
||||
#_
|
||||
(is (= {:errors [(error/syntax ::error/invalid-placeholders #{'f})]}
|
||||
(is (= {:errors [(error/syntax ::error/invalid {:type :placeholders} {:data #{'f}})]}
|
||||
(utils/interpolate {'e 2.369} "${f:1.2f}"))))
|
||||
|
|
Loading…
Reference in New Issue