Skip to content

Instantly share code, notes, and snippets.

@cgrand

cgrand/doc.clj

Created Sep 14, 2017
Embed
What would you like to do?
Documenting specs inline
(defmacro doc
"Returns a spec which acts in all points like the provided spec,
expect for describe/form where the docstring appears."
[docstring spec]
`(doc-impl ~docstring '~spec (delay (spec/spec ~spec))))
(defn doc-impl [docstring form delayed-spec]
(reify spec/Spec
(conform* [_ x] (spec/conform* @delayed-spec x))
(unform* [_ y] (spec/unform* @delayed-spec y))
(explain* [_ path via in x] (spec/explain* @delayed-spec path via in x))
(gen* [_ overrides path rmap] (spec/gen* @delayed-spec overrides path rmap))
(with-gen* [_ gfn] (spec/with-gen* @delayed-spec gfn))
(describe* [_]
`(doc ~docstring ~(if (keyword? form) form (spec/describe* @delayed-spec))))))
@gphilipp

This comment has been minimized.

Copy link

@gphilipp gphilipp commented Sep 15, 2017

Expect or except ?

@gphilipp

This comment has been minimized.

Copy link

@gphilipp gphilipp commented Sep 15, 2017

Christophe, can you give an example of usage with result ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment