Fork me on GitHub
#clojure-spec
<
2017-07-21
>
ikitommi09:07:50

@danieleneal @alex - gave a shot at the CLJ-2116: https://github.com/clojure/spec.alpha/pull/1. Idea is to support a optional conforming callback for conform & explain, allowing specs to be separated from conforming. Would be used like this:

(deftest conforming-callback-test
  (let [string->int-conforming
        (fn [spec]
          (condp = spec
            int? (fn [_ x _]
                   (cond
                     (int? x) x
                     (string? x) (try
                                   (Long/parseLong x)
                                   (catch Exception _
                                     ::s/invalid))
                     :else ::s/invalid))
            :else nil))]

    (testing "no conforming callback"
      (is (= 1 (s/conform int? 1)))
      (is (= ::s/invalid (s/conform int? "1"))))

    (testing "with conforming callback"
      (is (= 1 (s/conform int? 1 string->int-conforming)))
      (is (= 1 (s/conform int? "1" string->int-conforming))))))

scaturr10:07:45

Are there any known issues with clojure.test.check and multi arity functions?

scaturr10:07:07

for some reason when I try to run (st/check make-action) my repl just hangs forever

scaturr10:07:02

same thing out of the repl too - lein test just hangs (running generative tests via clojure.test.check in my normal test suite)

scaturr10:07:55

I did verify that I could generate data for all the (s/def) expressions individually - that seems to work

gfredericks11:07:04

@scaturr did you try generating (s/cat :type ::type :error? ::error? :payload (s/? ::payload)) as well?

scaturr11:07:05

I did not - I will try that now

scaturr11:07:00

yes that worked 😕

gfredericks11:07:08

I'm trying this out too

gfredericks11:07:16

can't reproduce; check ran fine for me

scaturr11:07:26

I changed ::payload back to map? for that example

scaturr11:07:33

instead of string? - though both produce the error

scaturr11:07:08

what version of test.check are you running?

scaturr11:07:49

thank you for your help by the way 🙂

gfredericks11:07:02

probably 0.10.0-alpha2

scaturr11:07:42

I’m on 0.9.0

scaturr11:07:47

I’ll try updating

scaturr11:07:34

that fixes it

scaturr11:07:41

thank you so much

gfredericks11:07:00

well I'd certainly like to know what the difference is, but I don't think it matters enough to look into 😕

gfredericks11:07:11

but if you figure it out, let me know 🙂

Alex Miller (Clojure team)13:07:21

@ikitommi noted. I'm not going to do anything with it until I get a chance to ask Rich about it

wilkerlucio16:07:05

hello people, for those looking at how to do coercion with specs, spec-coerce leverages your spec definitions to coerce value types 🙂 https://github.com/wilkerlucio/spec-coerce