Open lread opened 2 years ago
I didn't know deep-diff2
did that; it seems like a very cool and useful feature!
I think this is definitely possible, especially given we have a notion of mismatch weights (for example the weight of sequence mismatch is the sum of the mismatch weights of each mismatching element). Currently we mostly use this in the in-any-order
matcher to try to find the minimal mismatch. In in-any-order
this leads to some pretty poor performance but maybe there is a way to do this missing/extraneous element detection for the more strict default sequence matching logic that doesn't incur much additional overhead. I'll try to look into it in the next days.
cheers and glad to hear you've been enjoying using the lib :)
Thanks for the reply @philomates!
If matcher-combinators were to adopt this new behaviour for sequences, I don't see a need for it to support the current behaviour. Does that make sense to you too?
@lread I think https://github.com/nubank/matcher-combinators/pull/187 might cover the ideas you've listed here if you want to check it out
Very exciting @philomates! I'll try it out shortly and provide feedback in the PR!
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:
The mismatch is reported as:
Snapshot for colours:
Same idea for an unexpected extra element in a sequence:
Gives us:
deep-diff2 behaviour
For comparison, let's use deep-diff2 to show what I mean by "recovering".
Snapshot to show colours: We see that deep-diff2 sees
2
as missing and then continues to match3
and4
.It also handles extra elements like this:
We see
2
as an unexpected addition but shows3
and4
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:And the extra
2
maybe like so:Next Steps
If the above seems like a good idea, would be happy to help in any way that makes sense.