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

[feature request] assertEquals multiline string diffs #929

Closed
andykais opened this issue May 20, 2021 · 4 comments · Fixed by #948
Closed

[feature request] assertEquals multiline string diffs #929

andykais opened this issue May 20, 2021 · 4 comments · Fixed by #948

Comments

@andykais
Copy link

currently assertEquals will pretty print js object differences
screenshot(616)

but will show multiline string diffs as a single blob
screenshot(617)
The actual diff here is pretty much unreadible so I often end up writing the changes to a file and using git diff or the diff command to see the actual changes.

It would be great if assertEquals could show multiline string diffs in a similar manner to git diff

@andykais andykais changed the title [feature request] assertEquals multiline diff [feature request] assertEquals multiline string diffs May 20, 2021
@lowlighter
Copy link
Contributor

Do you mean something like git diff --word-diff ?

@andykais
Copy link
Author

andykais commented Jun 1, 2021

@lowlighter sure, but even a normal git diff would be an improvement. That is a multiple line string comparison (see the \n characters), but it reads as a single line comparison

@ebebbington
Copy link

I too think this would be nice to have, there's plenty of times where im wanting to assert a very large string ie help output from a cli - i have to just sift through every character and compare if the first line in the expected ends with the same character as the actual, then the same for line 2, and so on 😆

Granted i'm the on with massive strings so i brought it upon myself, but would be nice to have multiline string diffs (eg not escaping newlines or colour encoding)

@lowlighter
Copy link
Contributor

lowlighter commented Jun 2, 2021

So I made a prototype for both multi-lines/words diffs which render like below:

image
image

Basically if both operands are string, a custom string tokenizer is called before entering diff() function.

I'm not sure how to auto-switch from multi-lines diff to word-diff yet though 🤔
I think words is more readable when few words are edited so maybe a threshold to switch to multi-lines based on number of words edited would be the best.

@ebebbington Not escaping colours seems a bit tricky, since the diff renderer currently uses colors, not sure what would be the right way to do this

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 a pull request may close this issue.

3 participants