|
9 | 9 | [matcher-combinators.matchers :as m]
|
10 | 10 | [matcher-combinators.result :as result]
|
11 | 11 | [matcher-combinators.test :refer [match?]]
|
12 |
| - [matcher-combinators.test-helpers :as test-helpers :refer [no-match? abs-value-matcher]]) |
13 |
| - (:import [matcher_combinators.model Mismatch Missing InvalidMatcherContext InvalidMatcherType])) |
| 12 | + [matcher-combinators.test-helpers :refer [abs-value-matcher no-match?]]) |
| 13 | + (:import [matcher_combinators.model InvalidMatcherContext InvalidMatcherType Mismatch Missing])) |
14 | 14 |
|
15 | 15 | (defn any? [_x] true)
|
16 | 16 |
|
|
362 | 362 | actual)))))
|
363 | 363 |
|
364 | 364 | (deftest strictly-equals-matcher
|
365 |
| - (testing "passing case with one level map" |
366 |
| - (is (match? (m/strictly-equals {:a :b}) |
367 |
| - {:a :b}))) |
368 |
| - |
369 |
| - (testing "passing case with multi level map" |
370 |
| - (is (match? (m/strictly-equals {:a :b :c {:d {:e :f}}}) |
371 |
| - {:a :b :c {:d {:e :f}}}))) |
372 |
| - |
373 |
| - (testing "failing case with one level map" |
374 |
| - (is (no-match? (m/strictly-equals {:a :b}) |
375 |
| - {:a :b :c :d}))) |
376 |
| - |
377 |
| - (testing "failing case with multi level map" |
378 |
| - (is (no-match? (m/strictly-equals {:a :b :c {:d {:e :f}}}) |
379 |
| - {:a :b :c {:d :e}})))) |
| 365 | + (testing "nested maps" |
| 366 | + (testing "passing case" |
| 367 | + (is (match? (m/strictly-equals {:user1 {:id 5 :name "hennix"} |
| 368 | + :user2 {:id 3 :name "flynt"}}) |
| 369 | + {:user1 {:id 5 :name "hennix"} |
| 370 | + :user2 {:id 3 :name "flynt"}}))) |
| 371 | + |
| 372 | + (testing "`strictly-equals` fails when nested maps have extra keys" |
| 373 | + (is (no-match? (m/strictly-equals {:user1 {:id 5} |
| 374 | + :user2 {:id 3}}) |
| 375 | + {:user1 {:id 5 :name "hennix"} |
| 376 | + :user2 {:id 3 :name "flynt"}}))) |
| 377 | + |
| 378 | + (testing "`equals` still matchs when nested maps have extra keys" |
| 379 | + (is (match? (m/equals {:user1 {:id 5} |
| 380 | + :user2 {:id 3}}) |
| 381 | + {:user1 {:id 5 :name "hennix"} |
| 382 | + :user2 {:id 3 :name "flynt"}}))) |
| 383 | + |
| 384 | + (testing "`strictly-equals` is similar to using `equals` in each map" |
| 385 | + (is (no-match? (m/equals {:user1 (m/equals {:id 5}) |
| 386 | + :user2 (m/equals {:id 3})}) |
| 387 | + {:user1 {:id 5 :name "hennix"} |
| 388 | + :user2 {:id 3 :name "flynt"}})))) |
| 389 | + |
| 390 | + (testing "functions" |
| 391 | + (testing "`strictly-equals` does not apply `equals` to functions" |
| 392 | + (is (match? (m/strictly-equals {:x odd?}) |
| 393 | + {:x 1}))) |
| 394 | + |
| 395 | + (testing "`equals` should be aplied directly to the function to fail" |
| 396 | + (is (no-match? (m/equals {:x (m/equals odd?)}) |
| 397 | + {:x 1})))) |
| 398 | + |
| 399 | + (testing "regex" |
| 400 | + (testing "`strictly-equals` does not apply `equals` to regex" |
| 401 | + (is (match? (m/strictly-equals {:x #"\s+"}) |
| 402 | + {:x "abc"}))) |
| 403 | + |
| 404 | + (testing "`equals` should be aplied directly to the regex to fail" |
| 405 | + (is (no-match? (m/equals {:x (m/equals #"\s+")}) |
| 406 | + {:x "abc"}))))) |
380 | 407 |
|
381 | 408 | (def gen-processable-double
|
382 | 409 | (gen/double* {:infinite? false :NaN? false}))
|
|
0 commit comments