This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-31
Channels
- # architecture (1)
- # aws (23)
- # beginners (13)
- # boot (18)
- # cider (5)
- # clara (1)
- # cljs-dev (22)
- # cljsjs (9)
- # cljsrn (28)
- # clojure (120)
- # clojure-canada (12)
- # clojure-dev (6)
- # clojure-italy (4)
- # clojure-korea (1)
- # clojure-russia (18)
- # clojure-sg (8)
- # clojure-spec (45)
- # clojure-uk (12)
- # clojurescript (240)
- # component (4)
- # cursive (17)
- # datomic (91)
- # editors-rus (4)
- # figwheel (2)
- # flambo (6)
- # hoplon (163)
- # instaparse (6)
- # jobs (1)
- # leiningen (2)
- # luminus (5)
- # om (22)
- # om-next (2)
- # onyx (35)
- # perun (15)
- # play-clj (1)
- # protorepl (4)
- # re-frame (106)
- # reagent (4)
- # ring (106)
- # schema (1)
- # spacemacs (17)
- # untangled (40)
- # yada (14)
errr… so I have spec like this:
#?(:clj (defn uuid-str-gen [] (gen/return (str (java.util.UUID/randomUUID))))
:cljs (defn uuid-str-gen [] (gen/return (str (random-uuid)))))
(s/def ::uuid (s/with-gen (s/and
string?
#(re-matches uuid-regex %)
uuid-str?)
uuid-str-gen))
for uuid vals. A bit bulky, I couldn’t find anything better. my problem now, if another spec includes it it always generates same uuids. How do I fix that?(gen/sample (s/gen ::uuid))
("06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2" "06cd3a07-98e0-4ee2-bce8-fa0b9e96d9e2”)
`I don't see it in my REPL, but I've seen it in a talk: https://www.dropbox.com/s/w1ktte022j5xy4o/Screenshot%202016-08-31%2014.00.08.png?dl=0
@sveri very rough but maybe it helps https://gist.github.com/martinklepsch/e1366008c5a478b33c00d324314da4fd
@martinklepsch thanks, so basically its: 1. validate input with spec 2. try to parse result and display some useful text
right. Do all of that on a form level and do some basic dirty?
tracking
Rich checked in a round of perf improvements to master yesterday which fixed some hot spots
When I try to run check
on a function that I’ve spec’d with fdef
, it fails with the cause “Unable to construct gen at: [] for : clojure.spec$…"
@mschmele you should (generally) use the predicates on their own instead of wrapping in an anonymous function. Otherwise you won.t get generators for the functions that have them.
Okay, I just saw an example that was formatted that way and it seemed to work. Changing that now
also you should just use the specs inside fdef, no need for assert or valid which will probably give strange results
is there a concise way to get a keyword?
s/def
but the one that always generates short keywords?
because this looks awful;
(s/def ::keyword (s/with-gen keyword? (fn [] (gen/fmap #(keyword %)
(gen/such-that #(and (> 10 (count %))
(< 0 (count %)))
(gen/string-alphanumeric) 1000)))))
(s/def ::short-keyword (s/with-gen keyword? (fn [] (gen/fmap #(keyword %)
(gen/such-that #(and (> 10 (count %))
(< 0 (count %)))
(gen/string-alphanumeric) 1000)))))
(s/def ::keyword ::short-keyword)
(s/def ::keyword2 ::short-keyword)
@sattvik doing it that way makes the spec validate that the keyword is short, which you may not want, and also makes for slow generators