Created
July 10, 2016 15:17
-
-
Save dball/e096fc7fb600fbc53fd94e4b367cf68f to your computer and use it in GitHub Desktop.
This file contains hidden or 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