clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Aron 2020-08-27T10:43:27.094200Z

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.

Aron 2020-08-27T10:46:04.096300Z

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

2020-08-27T11:17:10.099700Z

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

👍 3
Aron 2020-08-27T17:55:23.101600Z

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

Aron 2020-08-27T17:56:52.102100Z

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

Aron 2020-08-27T17:57:01.102400Z

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

vlaaad 2020-08-27T18:15:14.102500Z

What is the problem you are solving @ashnur?

Aron 2020-08-27T18:22:30.103Z

Which one? 🙂

Aron 2020-08-27T18:22:59.103300Z

I am writing automated integration tests.

vlaaad 2020-08-27T18:59:25.103700Z

for system that validates emails? 🙂

Aron 2020-08-27T19:10:20.106500Z

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

vlaaad 2020-08-27T19:12:35.108300Z

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 .

vlaaad 2020-08-27T19:18:38.112Z

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

2020-08-27T23:56:13.116500Z

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