From c3a14c96d1c5baa6f0a049f113d07b720f16cd85 Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Fri, 29 Jul 2022 12:39:40 +0200 Subject: [PATCH] Added concat-str-vec with string-vector? pred --- src/main/cljc/dda/c4k_common/common.cljc | 5 +++++ src/main/cljc/dda/c4k_common/predicate.cljc | 8 +++++++- src/test/cljc/dda/c4k_common/predicate_test.cljc | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 33eceb4..360f83c 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -58,6 +58,11 @@ (into [] (apply concat vs))) +(defn-spec concat-str-vec cp/string-vector? + [& vs (s/* seq?)] + (into [] + (apply concat vs))) + (defn generate-common [my-config my-auth config-defaults k8s-objects] (let [resulting-config (merge config-defaults my-config my-auth)] (cs/join diff --git a/src/main/cljc/dda/c4k_common/predicate.cljc b/src/main/cljc/dda/c4k_common/predicate.cljc index fa890d1..3c0cadb 100644 --- a/src/main/cljc/dda/c4k_common/predicate.cljc +++ b/src/main/cljc/dda/c4k_common/predicate.cljc @@ -14,7 +14,7 @@ (and (string? input) (some? (re-matches #"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)" input)))) -(defn string-of-separated-by? +(defn string-of-separated-by? [spec-function separator input] (every? true? (map spec-function (str/split input separator)))) @@ -44,3 +44,9 @@ (fqdn-string? (first split-string)) (port-number? (edn/read-string (second split-string))))))) +(defn string-vector? + [input] + (and (vector? input) + (every? true? + (map #(string? %) input)))) + diff --git a/src/test/cljc/dda/c4k_common/predicate_test.cljc b/src/test/cljc/dda/c4k_common/predicate_test.cljc index 790c006..59a4333 100644 --- a/src/test/cljc/dda/c4k_common/predicate_test.cljc +++ b/src/test/cljc/dda/c4k_common/predicate_test.cljc @@ -49,4 +49,9 @@ (is (true? (cut/host-and-port-string? "test.de:1234"))) (is (false? (cut/host-and-port-string? "test.de,1234"))) (is (false? (cut/host-and-port-string? "test.123:1234"))) - (is (false? (cut/host-and-port-string? "test.de:abc")))) \ No newline at end of file + (is (false? (cut/host-and-port-string? "test.de:abc")))) + +(deftest test-string-vector? + (is (true? (cut/string-vector? ["hallo" "welt" "!"]))) + (is (false? (cut/string-vector? ["hallo" 1 "welt" "!"]))) + (is (false? (cut/string-vector? "hallo welt!")))) \ No newline at end of file