Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ For example:
(is (match? {:name/first "Alfredo"}
{:name/first "Alfredo"
:name/last "da Rocha Viana"
:name/suffix "Jr."}))))
:name/suffix "Jr."})))

(deftest test-matching-nested-datastructures
;; Maps, sequences, and sets follow the same semantics whether at
Expand Down Expand Up @@ -209,7 +209,7 @@ The `via` matcher can help us out with this:
```clojure
(let [result {:payloads ["{:foo :bar :baz :qux}"]}]
(is (match? {:payloads [(m/via read-string {:foo :bar})]}
{:payloads result})))
result)))
```

`via`, when paired with `match-with`, can be used to apply `actual` pre-processing before applying an underlying matcher:
Expand All @@ -219,7 +219,7 @@ The `via` matcher can help us out with this:
(is (match? (m/match-with
[vector? (fn [expected] (m/via sort expected))]
{:payloads [1 2 3]})
{:payloads (shuffle [3 2 1])}))))
{:payloads (shuffle [3 2 1])})))
```

In this example we decorate `vector?`'s matcher to first sort the `actual` and then do matching.
Expand All @@ -236,12 +236,13 @@ Negative matchers, that is, those asserting the absence of something, are genera

```clojure
(deftest avoid-negative-matchers
(testing "normal assertion that `:a` is present"
(match? {:a any?}
actual))
(testing "double negation version"
(match? (matcher-combinators.matchers/mismatch {:a matcher-combinators.matchers/absent})
actual)))
(let [actual {:a 1}]
(testing "normal assertion that `:a` is present"
(is (match? {:a any?}
actual)))
(testing "double negation version"
(is (match? (matcher-combinators.matchers/mismatch {:a matcher-combinators.matchers/absent})
actual)))))
```

### building new matchers
Expand Down Expand Up @@ -272,8 +273,8 @@ For convenience we've also added the built-in matcher `nested-equals` to reduce

``` clojure
(deftest exact-map-matching-with-match-with
(is (match? (m/nested-equals {:a {:b {:c odd?}}}))
{:a {:b {:c 1}}}))
(is (match? (m/nested-equals {:a {:b {:c odd?}}})
{:a {:b {:c 1}}})))
```

## Development
Expand Down
Loading