|
15 | 15 | Commonly, a dev-only user namespace will require this namespace." |
16 | 16 | (:require |
17 | 17 | #?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]] |
18 | | - :clj [clojure.test :as t :refer [is are deftest testing]]) |
19 | | - #?(:cljs [matcher-combinators.cljs-test] |
20 | | - :clj [matcher-combinators.clj-test]))) |
21 | | - |
22 | | -(declare ^{:arglists '([matcher actual])} |
23 | | - match?) |
24 | | -(declare ^{:arglists '([type->matcher matcher actual])} |
25 | | - match-with?) |
26 | | -(declare ^{:arglists '([matcher actual] |
27 | | - [exception-class matcher actual])} |
28 | | - thrown-match?) |
29 | | -(declare ^{:arglists '([delta matcher actual])} |
30 | | - match-roughly?) |
| 18 | + :clj [clojure.test :as t :refer [is are deftest testing]]) |
| 19 | + #?(:cljs [matcher-combinators.cljs-test] |
| 20 | + :clj [matcher-combinators.clj-test]))) |
| 21 | + |
| 22 | +(defn match? |
| 23 | + "Asserts that the `actual` matches the `expected`, where the `expected` can be a value, a predicate function, or a matcher-combinator. |
| 24 | +
|
| 25 | +(is (match? [0 1 2] (range 3))) |
| 26 | +(is (match? (complement empty?) (range 3))) |
| 27 | +(is (match? (matcher-combinators.matchers/in-any-order [zero? odd? even?]) (range 3)))" |
| 28 | + [matcher actual] |
| 29 | + (throw (#?(:cljs js/Error. :clj AssertionError.) |
| 30 | + "Should only be invoked within a `clojure.test/is` form"))) |
| 31 | + |
| 32 | +(defn match-with? |
| 33 | + "DEPRECATED: Use (match? (matcher-combinators.matchers/match-with <type->matcher> <expected>) <actual>) instead." |
| 34 | + [type->matcher matcher actual] |
| 35 | + (throw (#?(:cljs js/Error. :clj AssertionError.) |
| 36 | + "Should only be invoked within a `clojure.test/is` form"))) |
| 37 | + |
| 38 | +(defn thrown-match? |
| 39 | + "Asserts that evaluating expr throws an exception where the excpetion's ex-data satisfies the provided matcher. |
| 40 | +
|
| 41 | +2-arity: (is (thrown-with-match? matcher expr)) |
| 42 | +3-arity: (is (thrown-with-match? exception-class matcher expr))" |
| 43 | + ([matcher actual] |
| 44 | + (throw (#?(:cljs js/Error. :clj AssertionError.) |
| 45 | + "Should only be invoked within a `clojure.test/is` form"))) |
| 46 | + ([exception-class matcher actual] |
| 47 | + (throw (#?(:cljs js/Error. :clj AssertionError.) |
| 48 | + "Should only be invoked within a `clojure.test/is` form")))) |
| 49 | + |
| 50 | +(defn match-roughly? |
| 51 | + "DEPRECATED: Instead use (match? (matcher-combinators.matchers/match-with [number? (matcher-combinators.matchers/within-delta 0.01M)] <expected>) <actual>)" |
| 52 | + [delta matcher actual] |
| 53 | + (throw (#?(:cljs js/Error. :clj AssertionError.) |
| 54 | + "Should only be invoked within a `clojure.test/is` form"))) |
31 | 55 |
|
32 | 56 | #?(:clj |
33 | 57 | (def build-match-assert |
|
0 commit comments