Description
Thanks!
First thanks so much for this library, I've used it with great pleasure on some cljdoc tests and am now proposing its use on clj-kondo tests.
Observation
matcher-combinators behaviour
While exploring matcher-combinators for clj-kondo tests, I noticed when an item is missing from a sequence, matcher-combinators does not seem to attempt to recover after the missing element.
Given test:
(deftest lee-test
(is (match? [1 2 3 4] [1 3 4])))
The mismatch is reported as:
FAIL in (lee-test) (java_test.clj:70)
expected: (match? [1 2 3 4] [1 3 4])
actual: [1
(mismatch (expected 2) (actual 3))
(mismatch (expected 3) (actual 4))
(missing 4)]
Same idea for an unexpected extra element in a sequence:
(deftest lee-test
(is (match? [1 3 4] [1 2 3 4])))
Gives us:
FAIL in (lee-test) (java_test.clj:71)
expected: (match? [1 3 4] [1 2 3 4])
actual: [1
(mismatch (expected 3) (actual 2))
(mismatch (expected 4) (actual 3))
(unexpected 4)]
deep-diff2 behaviour
For comparison, let's use deep-diff2 to show what I mean by "recovering".
❯ clj -Sdeps '{:deps {lambdaisland/deep-diff2 {:mvn/version "RELEASE"}}}'
Clojure 1.11.1
user=> (require '[lambdaisland.deep-diff2 :as ddiff])
nil
user=> (ddiff/pretty-print (ddiff/diff [1 2 3 4] [1 3 4]))
[1 -2 3 4]
nil
Snapshot to show colours:
We see that deep-diff2 sees 2
as missing and then continues to match 3
and 4
.
It also handles extra elements like this:
user=> (ddiff/pretty-print (ddiff/diff [1 3 4] [1 2 3 4]))
[1 +2 3 4]
We see 2
as an unexpected addition but shows 3
and 4
as matching.
To Consider
Would it be viable and/or make sense for matcher-combinators to compare sequences the same way that deep-diff2 does?
This would mean the missing 2
would might be reported like so:
expected: (match? [1 2 3 4] [1 3 4])
actual: [1
(missing 2)
3
4]
And the extra 2
maybe like so:
expected: (match? [1 3 4] [1 2 3 4])
actual: [1
(unexpected 2)
3
4]
Next Steps
If the above seems like a good idea, would be happy to help in any way that makes sense.