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

Print string-based diff if there's a mismatch of two strings #50

Open
or opened this issue Sep 28, 2023 · 3 comments
Open

Print string-based diff if there's a mismatch of two strings #50

or opened this issue Sep 28, 2023 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@or
Copy link

or commented Sep 28, 2023

I sometimes need to write tests for functions that output strings, in particular multi-line strings. Right now deep-diff2 will just say -<expected-string> +<actual-string>, which isn't very useful for longer strings and strings containing newlines.
Right now I try to work around this by splitting the strings on newlines and letting deep-diff2 diff the arrays, which at least will highlight the lines with changes, but it's not great.

I think it'd be useful to print a string-based diff, like git-diff would, if both expressions for a mismatch are string.

For no newlines they could still be printed in place, but for newlines it likely would make sense to introduce a linebreak and then show the diff without worrying about indentation.

I found deep-diff2.printer-impl/print-mismatch, and (and (string? (:- expr)) (string? (:+ expr))) seems like an easy enough condition there, so I'm playing around with it.

Would you consider this for deep-diff2, or do you see problems with the approach? Perhaps it could be an option to not break any existing consumers.

@alysbrooks
Copy link
Member

I experimented with something similar: #46. The way the screenshot is displaying it is probably not very readable, however. I think implementing a condition for print-mismatch like you suggest could be a way to make that more readable.

@or
Copy link
Author

or commented Nov 16, 2023

Ah, cool. I only checked the issues, didn't see there already was a PR. I'm not so sure about an edit difference and the structured representation of the diff.
I've been using a version that displays the diff based on io.github.java-diff-utils/java-diff-utils, so it only works for CLJ.

Making this customizable with a plugin, maybe with a multimethod, might be best to not break any current users and to allow different ways to diff the string.

This is an example of my current implementation:
Screenshot 2023-11-16 at 20 06 48

@lambduhh lambduhh added the good first issue Good for newcomers label Mar 13, 2024
@lambduhh
Copy link

lambduhh commented Mar 13, 2024

Marking as "good first issue" since most of legwork has been done and a draft PR #46 exists addressing the issue.

@lambduhh lambduhh moved this to Candidate in Lambda Island Open Source Mar 13, 2024
@lambduhh lambduhh added the enhancement New feature or request label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: Candidate
Development

No branches or pull requests

3 participants