Last active
October 15, 2016 20:52
-
-
Save samedhi/3ec2d55f2a9b554c74737b347a911210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns vidiot.listener.paths | |
(:require | |
[cljs.spec :as s] | |
[cljs.spec.impl.gen :as gen] | |
[cljs.spec.test :as stest])) | |
(def path (s/coll-of (s/with-gen string? #(s/gen #{"a" "b" "c" "d"})) | |
:min-count 1 | |
:kind vector? | |
:into [])) | |
(s/def ::path | |
(s/with-gen | |
path | |
(fn [] (gen/fmap #(vec (take 5 %)) (s/gen path))))) | |
(defn subpaths [xs] | |
(-> (reductions conj [] xs) rest)) | |
(s/fdef subpaths | |
:args (s/cat :xs ::path) | |
:ret seq? | |
:fn (s/and | |
(s/coll-of ::path) | |
#(= (-> % :args :xs count) (-> % :ret count)))) | |
> (stest/summarize-results (stest/check `subpaths)) | |
{:spec | |
(fspec | |
:args | |
(cat :xs :vidiot.listener.paths/path) | |
:ret | |
seq? | |
:fn | |
(and | |
(coll-of :vidiot.listener.paths/path) | |
(fn* | |
[p1__38761#] | |
(= (-> p1__38761# :args :xs count) (-> p1__38761# :ret count))))), | |
:sym vidiot.listener.paths/subpaths, | |
:failure | |
{:cljs.spec/problems | |
({:path [:fn], | |
:pred :cljs.spec/unknown, | |
:val :args, | |
:via [:vidiot.listener.paths/path], | |
:in [0 0]} | |
{:path [:fn], | |
:pred :cljs.spec/unknown, | |
:val {:xs ["d"]}, | |
:via [:vidiot.listener.paths/path], | |
:in [0 1]} | |
{:path [:fn], | |
:pred :cljs.spec/unknown, | |
:val :ret, | |
:via [:vidiot.listener.paths/path], | |
:in [1 0]} | |
{:path [:fn], | |
:pred :cljs.spec/unknown, | |
:val (["d"]), | |
:via [:vidiot.listener.paths/path], | |
:in [1 1]}), | |
:cljs.spec.test/args (["d"]), | |
:cljs.spec.test/val {:args {:xs ["d"]}, :ret (["d"])}, | |
:cljs.spec/failure :check-failed}} | |
{:total 1, :check-failed 1} | |
;; So that fails, let us re-fdef subpaths. | |
;; (I have moved `(s/coll-of ::path)` into the :ret) | |
(s/fdef subpaths | |
:args (s/cat :xs ::path) | |
:ret (s/coll-of ::path) | |
:fn (s/and | |
#(= (-> % :args :xs count) (-> % :ret count)))) | |
> (stest/summarize-results (stest/check `subpaths)) | |
{:sym vidiot.listener.paths/subpaths} | |
{:total 1, :check-passed 1} | |
;; Why does this only work when I place it in the `:ret`? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment