From 6d520d3fa8cd786ead85718902464af4f8189b7c Mon Sep 17 00:00:00 2001 From: jerger Date: Fri, 29 Jul 2022 13:46:53 +0200 Subject: [PATCH] fix spec for concat-vec & added tests --- src/main/cljc/dda/c4k_common/common.cljc | 7 +---- src/main/cljc/dda/c4k_common/predicate.cljc | 4 +-- .../cljc/dda/c4k_common/common_it_test.cljc | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/test/cljc/dda/c4k_common/common_it_test.cljc diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 360f83c..8bb53d9 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -54,12 +54,7 @@ coll)) (defn-spec concat-vec vector? - [& vs (s/* seq?)] - (into [] - (apply concat vs))) - -(defn-spec concat-str-vec cp/string-vector? - [& vs (s/* seq?)] + [& vs (s/* cp/string-sequence?)] (into [] (apply concat vs))) diff --git a/src/main/cljc/dda/c4k_common/predicate.cljc b/src/main/cljc/dda/c4k_common/predicate.cljc index 3c0cadb..f71ef6e 100644 --- a/src/main/cljc/dda/c4k_common/predicate.cljc +++ b/src/main/cljc/dda/c4k_common/predicate.cljc @@ -44,9 +44,9 @@ (fqdn-string? (first split-string)) (port-number? (edn/read-string (second split-string))))))) -(defn string-vector? +(defn string-sequence? [input] - (and (vector? input) + (and (sequential? input) (every? true? (map #(string? %) input)))) diff --git a/src/test/cljc/dda/c4k_common/common_it_test.cljc b/src/test/cljc/dda/c4k_common/common_it_test.cljc new file mode 100644 index 0000000..aa6b4a8 --- /dev/null +++ b/src/test/cljc/dda/c4k_common/common_it_test.cljc @@ -0,0 +1,26 @@ +(ns dda.c4k-common.common-it-test + (:require + #?(:clj [clojure.test :refer [deftest is are testing run-tests]] + :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) + [clojure.spec.test.alpha :as st] + [dda.c4k-common.common :as cut])) + +(st/instrument `cut/concat-vec) + +(deftest should-concat-vec + (is (= ["a1" "a2" "b1"] + (cut/concat-vec ["a1" "a2"] ["b1"]))) + (is (= ["a1" "a2" "b1"] + (cut/concat-vec '("a1" "a2") ["b1"]))) + (is (= ["a1" "a2" "b1"] + (cut/concat-vec '("a1" "a2") '("b1"))))) + +(deftest should-refuse-illegal-inputs + (is (thrown? Exception + (cut/concat-vec ["a1" "a2"] "b1"))) + (is (thrown? Exception + (cut/concat-vec ["a1" "a2"] nil))) + (is (thrown? Exception + (cut/concat-vec ["a1" "a2"] 2))) + (is (thrown? Exception + (cut/concat-vec {"a1" "a2"} [])))) \ No newline at end of file