Fork me on GitHub
#clojure-spec
<
2017-09-26
>
benh13:09:31

I want to generate strings of length 64. This code does the job, but seems a bit unwieldy. Is there a nicer way to do this?

(gen/generate (gen/fmap clojure.string/join 
                        (gen/vector clojure.test.check.generators/char-ascii
                                    64)))

mpenet13:09:38

same question as yesterday, I dont think so no

gfredericks13:09:50

if you like gen/let better syntactically, you can

(gen/let [chars (gen/vector test.check.generators/char-ascii 64)]
  (apply str chars))

gfredericks13:09:23

modulo getting all the namespaces right

mpenet13:09:53

I guess we could have something better in test.check for this

mpenet13:09:33

in the same vein as gen/vector

gfredericks13:09:38

Something specialized for strings?

gfredericks13:09:24

The whole string thing needs an overhaul if anybody can think of a reasonable approach to unicode

mpenet13:09:34

I know we can abuse string-for-regex in test.chuck for some of it

gfredericks13:09:10

That is a good example of the issues. Try generating matches for #".*" and see how much you like it

uwo16:09:01

is it likely or unlikely that s/def will accept docstrings in the future?

bfabry17:09:30

I wish there was a way to mark a function as impure in an fdef/fspec that had the consequence of turning on :ret validation for instrumentation and turning off validation of things against that fspec

fedreg17:09:05

Hi all, is there a way in spec to define a map with something like this: (s/def ::my-map :req-un [::name ::id (one-of ::role ::title)]?? ...So the data could be {:name "tom" :id "1" :role "mgr"} or {:name "tom" :id "1" :title "ceo"} for example. Thx!

bfabry17:09:51

it's been a while but what little is left of my Maths for CS class in my brain is saying you can't create an xor with just or and and. so I'd say you'd have to just use or + a predicate

fedreg17:09:01

I need an s/or but for the keys instead of just the vals

bfabry17:09:33

well s/keys supports or, so (s/def ::my-map :req-un [::name ::id (or ::role ::title)]) is perfectly valid

bfabry17:09:13

my point was just that {:name "tom" :id "1" :role "mgr" :title "ceo"} would be valid with that spec (as would your two examples)

fedreg17:09:34

ahh, missed that. Thanks for clarifying. Didn't realize it was that simple. Thx!

mrchance20:09:51

Hi, is there an automated way to get a spec for the output of conform, called with another given spec?

mrchance20:09:41

I mean:

> (def sp (s/cat :x double? :y double?))
> (s/conform sp [1.0 2.5])
{:x 1.0, :y 2.5} <- I'd like a spec describing this map

Alex Miller (Clojure team)20:09:57

no, although that’s been asked a few times.

mrchance20:09:14

Thanks! So if I wrote one myself, how would I check that they fit together? generative tests?

mrchance20:09:46

Ok, will play with it more, thanks 🙂