Fork me on GitHub
#clojure-spec
<
2020-08-27
>
Aron10:08:27

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.

Aron10:08:04

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. : )

Lennart Buit11:08:10

The pragmatic approach to validating emails: Check they contain an @ , and send an email to confirm 😉.

👍 9
Aron17:08:23

Now, what is the pragmatic approach to generate emails in clojurescript? 🙂

Aron17:08:52

(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)))

Aron17:08:01

this is regal, but I am not sure if it will work

vlaaad18:08:14

What is the problem you are solving @ashnur?

Aron18:08:30

Which one? 🙂

Aron18:08:59

I am writing automated integration tests.

vlaaad18:08:25

for system that validates emails? 🙂

Aron19:08:20

I am not sure why validation is coming up. I didn't speak about validation at all.

vlaaad19:08:35

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 .

vlaaad19:08:38

btw your domain generator implies 2-nd level domains like , but email hosts might be IP addresses (e.g. [email protected]). 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).

pip23:08:13

is there a really easy way to make human name generators with spec?

Alex Miller (Clojure team)01:08:04

A set is a valid spec that gens. So override the generator to gen from a known set of names