Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Oct 24, 2024
1 parent 14350e1 commit 6d82f01
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/flanders/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
;; Branches

EitherType
(->spec' [{:keys [choices]} ns f]
(->spec' [{:keys [tests choices]} ns f]
(when (seq tests)
(throw (ex-info (str "WARNING: "))))
(let [choices (->> choices
(map-indexed
(fn [i c]
Expand Down
44 changes: 42 additions & 2 deletions test/flanders/spec_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns flanders.spec-test
(:require
[clojure.string :as str]
[clojure.core.match :refer [match]]
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as stest]
Expand All @@ -12,8 +13,8 @@
(use-fixtures :once
(fn [t]
(stest/instrument 'fs/->spec)
(t)
(stest/unstrument 'fs/->spec)))
(try (t)
(finally (stest/unstrument 'fs/->spec)))))

(deftest test-valid-spec
(is
Expand Down Expand Up @@ -139,3 +140,42 @@
(s/form (fs/->spec (f/bool :equals true) "bool"))))
(is (= #{false}
(s/form (fs/->spec (f/bool :equals false) "bool")))))

(deftest conditional-test
(testing "predicates that return true for false work"
(is (s/valid?
(fs/->spec (f/conditional
boolean? f/any-bool)
(str `conditional-test))
false))
(is (s/valid?
(fs/->spec (f/conditional
false? (f/bool :equals false))
(str "conditional-test"))
false)))
(testing "predicates that return true for nil work"
(is (s/valid?
(fs/->spec (f/conditional
nil? f/any)
(str "conditional-test"))
nil)))
(testing "predicates that return false for false and nil work"
(is (not (s/valid?
(fs/->spec (f/conditional
(constantly false) f/any)
(str "conditional-test"))
false)))
(is (not (s/valid?
(fs/->spec (f/conditional
(constantly false) f/any)
(str "conditional-test"))
nil))))
(testing "condition predicates are taken into account in generators"
(is (s/exercise (fs/->spec (f/conditional
:else f/any-bool)
"conditional-test")))
(is (thrown-with-msg? Exception
#":spec\.generator/and-generator-failure"
(s/exercise (fs/->spec (f/conditional
(constantly false) f/any-bool)
"conditional-test"))))))

0 comments on commit 6d82f01

Please sign in to comment.