Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active May 30, 2016 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/0665078edb40fb0e1551c1d29655c2d6 to your computer and use it in GitHub Desktop.
Save borkdude/0665078edb40fb0e1551c1d29655c2d6 to your computer and use it in GitHub Desktop.
Spec for clojure.core./subs
(require '[clojure.spec :as s])
(s/fdef clojure.core/subs
;; the args are a string, integer and optionally another integer
:args (s/cat :s string? :start integer? :end (s/? integer?))
;; the return value should be a string
:ret string?
;; the input string should include the returned string
:fn #(clojure.string/includes? (-> % :args :s) (:ret %)))
(s/instrument #'clojure.core/subs)
(subs 1 2 3) ;; =>
;; ExceptionInfo Call to #'clojure.core/subs did not conform to spec:
;; In: [0] val: 1 fails at: [:args :s] predicate: string?
;; :clojure.spec/args (1 2 3)
;; clojure.core/ex-info (core.clj:4617)
(subs "foo" 1 2) ;; => "o", satisfies :ret and :fn obviously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment