deep-diff2
deep-diff2 copied to clipboard
WIP: Add within-string diffing
Imagine you get a failing test and you see a test failure. You see two strings, one expected and one actual, that look perfectly identical. Searching through these strings requires awkward scrolling or copying and pasting these strings into a diff application.
This is an early version of what this could look like in Kaocha:
It's actually straightforward to support string diffing, as they are collections of characters and perfectly supported by clj-diff. We just have to merge back the characters into strings so we don't get an unreadable diff.
This only enables within-string diffing when selected. I created a second arity for backward compatability. For future use, I added a general options hash-map. I think diff is a high-level function that might benefit from other options eventually.
A possible refinement would be to treat short strings as ("cat" and "kate") as atomic values that don't get diffed and use this new handling only on long strings.
We could also use the edit difference, I suppose, so that very similar strings get their differences highlighted and ones with large differences are just shown next each other. The reasoning would be if the difference is large, it's probably obvious. (In some cases, a large edit difference may mean you may not even need the expected value, as a lot of divergences might mean the function returned completely wrong data (say, HTML instead of plain text).) However, that seems like two much of a divergence for this PR and we would probably want to add that functionality for all sequences.
But I digress. I think this change represents a significant quality-of-life improvement, and we can add other functionality as use cases appear.