This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-10
Channels
- # aleph (4)
- # beginners (32)
- # cider (12)
- # cljs-dev (56)
- # cljsrn (7)
- # clojars (3)
- # clojure (165)
- # clojure-dev (33)
- # clojure-germany (1)
- # clojure-italy (27)
- # clojure-russia (7)
- # clojure-spec (24)
- # clojure-uk (62)
- # clojurescript (37)
- # core-async (7)
- # core-matrix (1)
- # cursive (9)
- # data-science (8)
- # datomic (8)
- # duct (4)
- # events (1)
- # figwheel (7)
- # flambo (3)
- # fulcro (43)
- # hoplon (25)
- # jobs-discuss (8)
- # lein-figwheel (4)
- # luminus (2)
- # off-topic (35)
- # om (8)
- # om-next (3)
- # onyx (30)
- # pedestal (62)
- # portkey (2)
- # protorepl (2)
- # re-frame (40)
- # reagent (9)
- # shadow-cljs (123)
- # specter (30)
- # sql (22)
- # testing (1)
- # uncomplicate (40)
- # unrepl (3)
- # vim (13)
- # yada (5)
Is there a good doc/faq/something on using spec's ability to generate mock data? Generating a string like "001212314" in particular? (meaning, n length, chars consisting of just 0-9?
spec itself does not really have something like that built in
you can use fmap to build a set of characters, then apply str to them
or use the regex gen support in the test.chuck library
I had been using test.chuck, but was curious if there was a more spec-native solution. thanks, I'll keep going with what I have!
test.chuck is rad
question, when i run (clojure.spec.test/check 'merge-users {:clojure.spec.test.check/opts {:num-tests 15 :max-size 2}})
it seems the num-tests option seems to be ignored. Am I passing the options for quick-check wrong? or is this to be expected and should I address my own expectations? 🙂
where I use the backtick instead of the quote (to help in markdown slack formatting)
In Clojure spec, how could I generate symbols or strings of max length 2 that contain only lowercased alphabetic characters? This works, but maybe it can be simplified?
(s/def ::varname
(s/with-gen symbol?
#(gen/fmap (fn [[i j l]]
(symbol
(str/lower-case (.substring
(str i j)
0 l))))
(gen/tuple (gen/char-alpha)
(gen/char-alpha)
(gen/choose 1 2)))))
min length 1?
I don't think that's terrible
(s/def ::varname
(s/with-gen symbol?
#(gen/fmap (fn [characters]
(symbol
(string/lower-case
(apply str characters))))
(gen/vector (gen/char-alphanumeric)
1
2))))
With spec/keys
(or spec in general), what’s the best way to express: One and only one of the keys ::foo
or ::bar
is required?
(s/keys :req [(or ::foo ::bar)]) and then and'd with a spec to enforce only one if you want that
The :req key vector supports 'and' and 'or' for key groups:
(s/keys :req [::x ::y (or ::secret (and ::user ::pwd))] :opt [::z])