Any suggestions on how to create a custom generator for this specification for an email address (or an alternative specification for an email address that can be used - I could just use string until I get chance to think about it properly...)
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
(s/def ::email-type (s/and string? #(re-matches email-regex %)))
When I use clojure.spec.gen.alpha/generate
on the returned generator from (clojure.spec.alpha/gen ::email-type)
I get an exception (my other specs will all generate data, just not this. So I am assuming I need a custom generator (it will be my first)
The error I get from generate is
Unhandled clojure.lang.ExceptionInfo
Couldn't satisfy such-that predicate after 100 tries.
{:pred #function[clojure.spec.alpha/gensub/fn--1876],
:gen {:gen #function[clojure.test.check.generators/such-that/fn--6372]},
:max-tries 100}
@jr0cket sorry to be that guy John but https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression
though if you're just doing this for fun, then w/e
Everything I do is for fun, unless someone is paying me a 6 figure sum to do otherwise (although I did still have some fun working at the bank).
🙂
check the test.chuck (no typo) library
Yeah, a big +1 for test.chuck
-- we use the regex generator a lot!
@jr0cket Additionally, lambdaisland/regal also has generators for regexes