Last active
May 30, 2016 10:48
-
-
Save borkdude/0665078edb40fb0e1551c1d29655c2d6 to your computer and use it in GitHub Desktop.
Spec for clojure.core./subs
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
(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