So, about this email generation thing. I know I am asking for a lot 🙂. But this is clojurescript, so my expectations are high because of the hype. However, the task to put together a generator for this http://emailregex.com/ in either of the suggested DSLs seem at least as daunting as just doing it from scratch, using built-ins.
Basically, I am blocked because it's such a huge task, I don't even want to start, I can write all the necessary tests by not generating emails at all. Some of the hand written email address generators that I have seen suggested or used in libraries are positively naive compared to what is out in the wild. : )
The pragmatic approach to validating emails: Check they contain an @
, and send an email to confirm 😉.
Now, what is the pragmatic approach to generate emails in clojurescript? 🙂
(def em-chr [:not "<" ">" "(" ")" "[" "]" "\\" "." "," ";" ":" "@" :whitespace :newline "\""])
(def em-id-wrd [:cat [:+ em-chr] [:* em-chr]])
(def em-str [:cat '\" :any '\"])
(def em-id [:alt em-id-wrd em-str])
(def em-domain [:cat [:+ [:class [\a \z] [\A \Z] :digit "-" "." ]] [:repeat [:class [\a \z] [\A \Z]] 2 63]])
(def email [:cat em-id "@" em-domain])
(prn (gen/generate (regal-gen/gen email)))
this is regal, but I am not sure if it will work
What is the problem you are solving @ashnur?
Which one? 🙂
I am writing automated integration tests.
for system that validates emails? 🙂
I am not sure why validation is coming up. I didn't speak about validation at all.
Sorry, too snarky... You need to decide what properties of strings representing emails matter for your tests involving emails. Nothing really matters, it's just stored? Use generator #".+@.+"
, who cares. Test needs to successfully send an email, but still has to generate different emails? Use my.email+<random-stuff-here>@gmail.com
.
btw your domain generator implies 2-nd level domains like <mailto:me@foo.com|me@foo.com>
, but email hosts might be IP addresses (e.g. me@123.123.123.0
). If your program runs in a corporate network, sysadmins might configure it to have internal resources as 1st-level domain (e.g. just me@corp
).
is there a really easy way to make human name generators with spec?