Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add within-string diffing #46

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

alysbrooks
Copy link
Member

@alysbrooks alysbrooks commented Jun 10, 2023

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:

2023-06-09_17-09

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.

Create a second arity for backward compatability. For future use, add a
general options hash-map. I think diff is a high-level function that
might benefit from other options eventually.
@alysbrooks alysbrooks changed the title WIP: Add within- string diffing WIP: Add within-string diffing Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant