Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active June 1, 2016 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/4b41b7c406c57228489b5edfb6ffe6a7 to your computer and use it in GitHub Desktop.
Save mfikes/4b41b7c406c57228489b5edfb6ffe6a7 to your computer and use it in GitHub Desktop.
Spec in Planck

Help get spec in shape for bootstrapped / self-hosted ClojureScript by using it with Planck.

If you find something broken, log tickets in the Planck issues log here, indicating that it is a spec issue.

Download:

Just put this binary on your path and chmod +x it.

Using

./planck-spec-alpha-3
Planck 1.13
ClojureScript 1.9.2
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
    Exit: Control+D or :cljs/quit or exit or quit
 Results: Stored in vars *1, *2, *3, an exception in *e

cljs.user=> (require '[cljs.spec :as s])
nil
cljs.user=> (s/def ::big-even (s/and integer? even? #(> % 1000)))
:cljs.user/big-even
cljs.user=> (s/explain ::big-even 5)
val: 5 fails predicate: even?
nil

Generators

To use generators, you need a version of test.check that has been updated to support bootstrap via TCHECK-105:

Download:

Now, just include the downloaded JAR on Planck's classpath and you are good to go with generators:

$ ./planck-spec-alpha-3 -c test.check-0.9.0-TCHECK-105.jar
Planck 1.13
ClojureScript 1.9.2
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
    Exit: Control+D or :cljs/quit or exit or quit
 Results: Stored in vars *1, *2, *3, an exception in *e

cljs.user=> (require 'clojure.test.check
       #_=>  'clojure.test.check.properties
       #_=>  'cljs.spec.impl.gen)
nil
cljs.user=> (in-ns 'cljs.spec.impl.gen)
nil
cljs.spec.impl.gen=> (generate (one-of [(gen-for-pred integer?) (gen-for-pred string?)]))
"L0r8bbP8bL"
cljs.spec.impl.gen=> (generate (such-that #(< 10000 %) (gen-for-pred integer?)))
42698
cljs.spec.impl.gen=> (let [reqs {:a (gen-for-pred number?)
                #_=>               :b (gen-for-pred keyword?)}
                #_=>         opts {:c (gen-for-pred string?)}]
                #_=>     (generate (bind (choose 0 (count opts))
                #_=>                 #(let [args (concat (seq reqs) (shuffle (seq opts)))]
                #_=>                   (->> args
                #_=>                     (take (+ % (count reqs)))
                #_=>                     (mapcat identity)
                #_=>                     (apply hash-map))))))
{:b :hYZC.d.O9b.f/fHW_E, :a -93}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment