Fork me on GitHub
#clojure-spec
<
2016-07-19
>
borkdude13:07:34

@seancorfield: any reason you're not using create-ns there?

Alex Miller (Clojure team)16:07:08

yeah, create-ns is equally valid

seancorfield16:07:53

@borkdude: I just lifted that code from the example @alexmiller pointed us all to 🙂

seancorfield22:07:12

Remind me: is there an easy way to create a generator based on a regular expression string?

seancorfield22:07:58

@gfredericks: Looks like I could use test.chuck for this? Although it says it doesn’t support anchors (yet)?

gfredericks22:07:19

seancorfield: yes and yes; are you using nontrivial anchors or just the ^...$ sort of thing?

gfredericks22:07:20

I can't remember if supporting general anchors was just a bit messy or if it was Really Hard the way backreferences &c. are

gfredericks22:07:22

or maybe backreferences are easier but lookahead/behind are hard

gfredericks22:07:24

man it's been a while

seancorfield22:07:27

I’m only using #"^…$"

seancorfield22:07:51

I can lift out the string between as a separate regex for generation if need be.

gfredericks22:07:06

that's exactly what I've done

gfredericks22:07:23

when in a similar position

gfredericks22:07:08

seancorfield: do you need the anchors there? e.g., re-matches already only matches the whole string

seancorfield22:07:47

I can change how it’s used (from re-find to re-matches).

gfredericks22:07:51

I think I was using anchors because prismatic/schema required them

seancorfield23:07:10

Looks like it doesn’t handle a pattern like [^\s] correctly maybe? I get spaces in the generated strings...

gfredericks23:07:44

that sure oughta work

gfredericks23:07:56

the thing is Surprisingly Robust™

gfredericks23:07:09

if it can't handle something it should throw an exception when you try to create the generator

gfredericks23:07:27

if you can share the regex I can try to reproduce

seancorfield23:07:43

Sure… let me test something smaller...

seancorfield23:07:18

Ah, no, it’s doing the right thing… that generated data is not what it seems 😐 Let me try something else...

seancorfield23:07:40

What appeared to be a space is actually the character for decimal code 55335 (!) so it looks like we’re good. Excellent!

gfredericks23:07:55

speaking of which I'd love to hear if anybody has any thoughts about string generators and unicode

gfredericks23:07:12

there are a couple test.check tickets about it and I have no idea what the best idea as

gfredericks23:07:42

it's a question of what a reasonable distribution is

seancorfield23:07:36

boot.user> (s/exercise ::m/email)
(["\"󍋩\"@[897.7.55.01]" "\"󍋩\"@[897.7.55.01]"] ["\"񟲮򽆷\"@R.V.zZl" "\"񟲮򽆷\"@R.V.zZl"] ["\"󮩣瘞󐼡\"@[562.0.2.073]" "\"󮩣瘞󐼡\"@[562.0.2.073]"] ["\"󄼧󥅲񻮈񼠚\"@[8.158.2.927]" "\"󄼧󥅲񻮈񼠚\"@[8.158.2.927]"] ["\"񑙾ƾ\"@4stFz.Tkc43.gZ4j.HRs-.mYf.VbC" "\"񑙾ƾ\"@4stFz.Tkc43.gZ4j.HRs-.mYf.VbC"] ["\"񧰡\"@[5.32.7.10]" "\"񧰡\"@[5.32.7.10]"] ["\"񝿙񉋹\"@[67.50.40.3]" "\"񝿙񉋹\"@[67.50.40.3]"] ["񲓉󦵇𰥽󎗪퐎𝭂񪰤󍽥.񢓞􉅎򲄿򀼃񇄭󊈭𔞜󛿑.󅷢㳍񳀰󢐜򐎭𴥿𼾍񧚎.􇯛𴳸.񡌞.񹦁򹇨򬊤.񦈽.󲟙@[6.9.905.824]" "񲓉󦵇𰥽󎗪퐎𝭂񪰤󍽥.񢓞􉅎򲄿򀼃񇄭󊈭𔞜󛿑.󅷢㳍񳀰󢐜򐎭𴥿𼾍񧚎.􇯛𴳸.񡌞.񹦁򹇨򬊤.񦈽.󲟙@[6.9.905.824]"] ["񢼿󁯲@9B.bCokjbO.6CJq2iCzy.cwIz" "񢼿󁯲@9B.bCokjbO.6CJq2iCzy.cwIz"] ["\"󐟳񣓭󪝏򄲹𢌎񶫺𪇤󻲺\"@[447.0.87.53]" "\"󐟳񣓭󪝏򄲹𢌎񶫺𪇤󻲺\"@[447.0.87.53]"])

gfredericks23:07:22

emails are pairs?

seancorfield23:07:35

exercise produces pairs

seancorfield23:07:44

Here’s the regex

(def email-regex
  "Sophisticated regex for validating an email address."
  (-> (str "(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|"
           "(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|"
           "(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))")
      re-pattern))

gfredericks23:07:12

those are some really good email addresses

seancorfield23:07:29

(I don’t remember where we got that from and, yes, I know you can’t really validate email addresses correctly with "just" a regex but this has been pretty good for us so far)

seancorfield23:07:59

But I’m very impressed that I could just throw that at test.chuck and it worked right out of the box!