fix spec for concat-vec & added tests

This commit is contained in:
jerger 2022-07-29 13:46:53 +02:00
parent 28b2381118
commit 6d520d3fa8
3 changed files with 29 additions and 8 deletions

View file

@ -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)))

View file

@ -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))))

View file

@ -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"} []))))