Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cljs spec #50

Merged
merged 21 commits into from
Oct 23, 2024
Prev Previous commit
Next Next commit
spec
  • Loading branch information
borkdude committed Oct 22, 2024
commit 0cf1a2c01be6e0ad5db6e04138271cd8fa11b01e
24 changes: 23 additions & 1 deletion src/sci/configs/cljs/spec/alpha.cljs
Original file line number Diff line number Diff line change
@@ -367,6 +367,26 @@
(clojure.core/assert (clojure.core/and (even? (count key-pred-forms)) (every? keyword? keys)) "alt expects k1 p1 k2 p2..., where ks are keywords")
`(s/alt-impl ~keys ~pred-forms '~pf)))

(macros/defmacro spec
"Takes a single predicate form, e.g. can be the name of a predicate,
like even?, or a fn literal like #(< % 42). Note that it is not
generally necessary to wrap predicates in spec when using the rest
of the spec macros, only to attach a unique generator

Can also be passed the result of one of the regex ops -
cat, alt, *, +, ?, in which case it will return a regex-conforming
spec, useful when nesting an independent regex.
---

Optionally takes :gen generator-fn, which must be a fn of no args that
returns a test.check generator.

Returns a spec."
[form & {:keys [gen]}]
(let [&env (ctx/get-ctx)]
(when form
`(s/spec-impl '~(res &env form) ~form ~gen nil))))

(def namespaces {'cljs.spec.alpha {'def (sci/copy-var def* sns)
'def-impl (sci/copy-var s/def-impl sns)
'and (sci/copy-var and sns)
@@ -405,7 +425,9 @@
'maybe-impl (sci/copy-var s/maybe-impl sns)
'alt (sci/copy-var alt sns)
'alt-impl (sci/copy-var s/alt-impl sns)
'describe (sci/copy-var s/describe sns)}
'describe (sci/copy-var s/describe sns)
'spec (sci/copy-var spec sns)
'spec-impl (sci/copy-var s/spec-impl sns)}
'cljs.spec.gen.alpha {'fmap (sci/copy-var gen/fmap gns)}})

(def config {:namespaces namespaces})
Loading