Skip to content

Instantly share code, notes, and snippets.

Last active Dec 30, 2019
What would you like to do?
'[cemerick.url :as url]
'[clojure.spec.alpha :as s]
'[clojure.spec.gen.alpha :as sgen])
(defn non-empty-string-alphanumeric
(sgen/such-that #(not= "" %)
(defn url-gen
"Generator for generating URLs; note that it may generate
http URLs on port 443 and https URLs on port 80, and only
uses alphanumerics"
(partial apply (comp str url/->URL))
;; protocol
(sgen/elements #{"http" "https"})
;; username
;; password
;; host
;; port
(sgen/choose 1 65535)
;; path
(sgen/fmap #(->> %
(interleave (repeat "/"))
(apply str))
;; query
{:max-elements 2})
;; anchor
(s/def ::url (s/with-gen
(s/and string?
(url/url %)
(catch Throwable t false)))
(sgen/generate (url-gen))
(s/valid? ::url "")

This comment has been minimized.

Copy link

@ioRekz ioRekz commented Jan 15, 2018

Added this gist to 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment