From 7713afdb388d90301f12ac035131fbac139bea6a Mon Sep 17 00:00:00 2001 From: az Date: Sun, 31 Oct 2021 08:51:03 +0100 Subject: [PATCH] add spec to yaml.clj and base64.clj --- src/main/clj/dda/c4k_common/base64.clj | 19 +++++++++++++------ src/main/clj/dda/c4k_common/yaml.clj | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/clj/dda/c4k_common/base64.clj b/src/main/clj/dda/c4k_common/base64.clj index 8ad3e00..47edf6d 100644 --- a/src/main/clj/dda/c4k_common/base64.clj +++ b/src/main/clj/dda/c4k_common/base64.clj @@ -1,14 +1,21 @@ (ns dda.c4k-common.base64 - (:import (java.util Base64))) + (:import (java.util Base64)) + (:require + [orchestra.core :refer [defn-spec]] + [orchestra.spec.test :as st] + [clojure.spec.alpha :as s])) -(defn encode - [string] + +(defn-spec encode string? + [string string?] (.encodeToString (Base64/getEncoder) (.getBytes string "UTF-8"))) -(defn decode - [string] +(defn-spec decode string? + [string string?] (String. (.decode (Base64/getDecoder) string) - "UTF-8")) \ No newline at end of file + "UTF-8")) + +(st/instrument) \ No newline at end of file diff --git a/src/main/clj/dda/c4k_common/yaml.clj b/src/main/clj/dda/c4k_common/yaml.clj index 95592ab..7c00bd3 100644 --- a/src/main/clj/dda/c4k_common/yaml.clj +++ b/src/main/clj/dda/c4k_common/yaml.clj @@ -2,18 +2,22 @@ (:require [clojure.java.io :as io] [clj-yaml.core :as yaml] - [clojure.walk])) + [clojure.walk] + [orchestra.core :refer [defn-spec]] + [orchestra.spec.test :as st] + [clojure.spec.alpha :as s])) -(defn cast-lazy-seq-to-vec - [lazy-seq] + +(defn-spec cast-lazy-seq-to-vec map? + [lazy-seq map?] (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) (into [] %) %) lazy-seq)) -(defn from-string [input] +(defn-spec from-string map? [input string?] (cast-lazy-seq-to-vec (yaml/parse-string input))) -(defn to-string [edn] +(defn-spec to-string string? [edn map?] (yaml/generate-string edn :dumper-options {:flow-style :block})) (defn dispatch-by-resource-name @@ -23,4 +27,6 @@ (defmulti load-resource dispatch-by-resource-name) (defmethod load-resource :clj [resource-name] - (slurp (io/resource resource-name))) \ No newline at end of file + (slurp (io/resource resource-name))) + +(st/instrument) \ No newline at end of file