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

Newline gets escaped in assert_snapshot if the string contains '\t' #715

Closed
jakobhellermann opened this issue Feb 1, 2025 · 0 comments · Fixed by #716
Closed

Newline gets escaped in assert_snapshot if the string contains '\t' #715

jakobhellermann opened this issue Feb 1, 2025 · 0 comments · Fixed by #716
Labels
bug Something isn't working

Comments

@jakobhellermann
Copy link
Contributor

What happened?

#713 changes the behaviour of assert_snapshot so that whenever there are control characters in the string, it gets printed using format! which will instead of literally.
When the string contains just \n and \t, this makes the diff less readable:

insta::assert_snapshot!(stdout, @"immutable_bookmark\timmutable\nmutable_bookmark\tmutable\nk\tworking_copy\ny\tmutable\nq\timmutable\nzq\tremote_commit\nzz\t(no description set)\nremote_bookmark@origin\tremote_commit\nalias_with_newline\t roots(\nsiblings\t@-+ ~@");

This could be fixed by treating \t as \n in has_control_chars:
https://github.com/mitsuhiko/insta/pull/713/files#diff-2666420e8389f1d842ce108018b05f3f68fa4b920f8c1793a3d4d01f21443544R696-R698


Personally I would go even further and prefer the old handling for \x1b (used for ANSI escape codes) as well.
Here's the diff for applying insta 1.42.1 on jj jakobhellermann/jj@7fdb978 and in my opinion it is much less readable.

in vscode

in vim

Reproduction steps

No response

Insta Version

1.42.1

rustc Version

rustc 1.85.0-nightly (45d11e51b 2025-01-01)

What did you expect?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant