This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn charseq-in | |
[& options] | |
(let [{:keys [count min-count max-count chars]} options] | |
(s/coll-of (or chars char?) | |
:count count | |
:min-count min-count | |
:max-count max-count))) | |
(defn string-in | |
[& options] | |
(let [charseq-spec (apply charseq-in options)] | |
(s/spec (s/and string? | |
#(s/valid? charseq-spec (vec (seq %)))) | |
:gen #(gen/fmap string/join (s/gen charseq-spec))))) | |
(s/def ::hostname-charseq | |
(let [chars (set (seq (str "abcdefghijklmnopqrstuvwxyz" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"0123456789")))] | |
(s/and | |
(charseq-in :chars (conj chars \-) :min-count 1 :max-count 64) | |
(s/cat :prefix (s/+ chars) | |
:sections (s/* (s/cat :hyphen (s/+ #{\-}) | |
:suffix (s/+ chars))))))) | |
(s/def ::hostname | |
(s/spec (s/and string? | |
#(s/valid? ::hostname-charseq (vec (seq %)))) | |
:gen #(gen/fmap string/join (s/gen ::hostname-charseq)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment