Move over token value reference check function

This commit is contained in:
Florian Schroedl 2024-10-03 15:14:38 +02:00
parent d58932c2e5
commit 5de1f450c1
5 changed files with 24 additions and 13 deletions

View file

@ -132,6 +132,17 @@
token))
(defn find-token-value-references
"Returns set of token references found in `token-value`.
Used for checking if a token has a reference in the value.
Token references are strings delimited by curly braces.
E.g.: {foo.bar.baz} -> foo.bar.baz"
[token-value]
(some->> (re-seq #"\{([^}]*)\}" token-value)
(map second)
(into #{})))
(defn group-by-type [tokens]
(let [tokens' (if (or (map? tokens)
(d/ordered-map? tokens))

View file

@ -44,8 +44,17 @@
:type :invalid}]
(t/is (thrown-with-msg? Exception #"expected valid token"
(apply ctob/make-token args)))
(t/is (false? (ctob/valid-token? {}))))))
(t/is (false? (ctob/valid-token? {})))))
(t/deftest find-token-value-references
(t/testing "finds references inside curly braces in a string"
(t/is (= #{"foo" "bar"} (ctob/find-token-value-references "{foo} + {bar}")))
(t/testing "ignores extra text"
(t/is (= #{"foo.bar.baz"} (ctob/find-token-value-references "{foo.bar.baz} + something")))))
(t/testing "ignores string without references"
(t/is (nil? (ctob/find-token-value-references "1 + 2"))))
(t/testing "handles edge-case for extra curly braces"
(t/is (= #{"foo" "bar"} (ctob/find-token-value-references "{foo}} + {bar}"))))))
(t/testing "token-set"
(t/deftest make-token-set