From d04a7fcca735bec191eea9ba5101be2f2da137a8 Mon Sep 17 00:00:00 2001 From: Gilvan Reis Date: Thu, 1 Feb 2024 17:02:42 -0300 Subject: [PATCH] Rename to nested-equals --- CHANGELOG.md | 4 ++-- README.md | 6 +++--- src/cljc/matcher_combinators/matchers.cljc | 2 +- test/clj/matcher_combinators/matchers_test.clj | 18 +++++++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b6ca6..98374f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). -## 3.9.0 / 2024-01-26 -- Add `strictly-equals` matcher, which always uses `equals` matcher at every level of nesting. +## 3.9.0 / 2024-02-01 +- Add `nested-equals` matcher, which always uses `equals` matcher at every level of nesting. ## 3.8.8 / 2023-09-04 - refine abbreviation logic to not descend into fully mismatched data, because diff --git a/README.md b/README.md index 0761da3..24edea3 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ for a specific value, e.g. - Note: Given that the default matcher for maps is `embeds`, nested maps continue being matched with embeds (instead of also being matched with `equals`). Check out 'Overriding default matchers' below for instructions on how to match nested maps with equals too. - sequence: matches when the `expected` sequences's matchers match the given sequence. Similar to midje's `(just expected)` - set: matches when all the elements in the given set can be matched with a matcher in `expected` set and each matcher is used exactly once. -- `strictly equals`: overrides map's default matchers to `equals`, using it for nested structures (see Overriding default matchers, below) +- `nested-equals`: overrides map's default matchers to `equals`, using it for nested structures (see Overriding default matchers, below) - `embeds` operates over maps, sequences, and sets - map: matches when the map contains some of the same key/values as the `expected` map. - sequence: order-agnostic matcher that will match when provided a subset of the `expected` sequence. Similar to midje's `(contains expected :in-any-order :gaps-ok)` @@ -265,11 +265,11 @@ For example, if you want to do exact map matching you need to use a log of `m/eq {:a {:b {:c 1 :extra-c 0} :extra-b 0} :extra-a 0}))) ``` -For convenience we've also added the built-in matcher `strictly-equals` to reduce this verbosity: +For convenience we've also added the built-in matcher `nested-equals` to reduce this verbosity: ``` clojure (deftest exact-map-matching-with-match-with - (is (match? (m/strictly-equals {:a {:b {:c odd?}}})) + (is (match? (m/nested-equals {:a {:b {:c odd?}}})) {:a {:b {:c 1}}})) ``` diff --git a/src/cljc/matcher_combinators/matchers.cljc b/src/cljc/matcher_combinators/matchers.cljc index 64a25e4..ef78842 100644 --- a/src/cljc/matcher_combinators/matchers.cljc +++ b/src/cljc/matcher_combinators/matchers.cljc @@ -33,7 +33,7 @@ (declare match-with) -(defn strictly-equals +(defn nested-equals "A matcher that always uses the `equals` matcher at every level of nesting. Useful given that matchers usually only change the first level of the data diff --git a/test/clj/matcher_combinators/matchers_test.clj b/test/clj/matcher_combinators/matchers_test.clj index e342f5e..ed3536c 100644 --- a/test/clj/matcher_combinators/matchers_test.clj +++ b/test/clj/matcher_combinators/matchers_test.clj @@ -361,16 +361,16 @@ :d (m/embeds {:e {:inner-e {:x 1 :y 2}}})}}) actual))))) -(deftest strictly-equals-matcher +(deftest nested-equals-matcher (testing "nested maps" (testing "passing case" - (is (match? (m/strictly-equals {:user1 {:id 5 :name "hennix"} + (is (match? (m/nested-equals {:user1 {:id 5 :name "hennix"} :user2 {:id 3 :name "flynt"}}) {:user1 {:id 5 :name "hennix"} :user2 {:id 3 :name "flynt"}}))) - (testing "`strictly-equals` fails when nested maps have extra keys" - (is (no-match? (m/strictly-equals {:user1 {:id 5} + (testing "`nested-equals` fails when nested maps have extra keys" + (is (no-match? (m/nested-equals {:user1 {:id 5} :user2 {:id 3}}) {:user1 {:id 5 :name "hennix"} :user2 {:id 3 :name "flynt"}}))) @@ -381,15 +381,15 @@ {:user1 {:id 5 :name "hennix"} :user2 {:id 3 :name "flynt"}}))) - (testing "`strictly-equals` is similar to using `equals` in each map" + (testing "`nested-equals` is similar to using `equals` in each map" (is (no-match? (m/equals {:user1 (m/equals {:id 5}) :user2 (m/equals {:id 3})}) {:user1 {:id 5 :name "hennix"} :user2 {:id 3 :name "flynt"}})))) (testing "functions" - (testing "`strictly-equals` does not apply `equals` to functions" - (is (match? (m/strictly-equals {:x odd?}) + (testing "`nested-equals` does not apply `equals` to functions" + (is (match? (m/nested-equals {:x odd?}) {:x 1}))) (testing "`equals` should be aplied directly to the function to fail" @@ -397,8 +397,8 @@ {:x 1})))) (testing "regex" - (testing "`strictly-equals` does not apply `equals` to regex" - (is (match? (m/strictly-equals {:x (m/regex #"\w+")}) + (testing "`nested-equals` does not apply `equals` to regex" + (is (match? (m/nested-equals {:x (m/regex #"\w+")}) {:x "abc"}))) (testing "`equals` should be aplied directly to the regex to fail"