Skip to content

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

@jakobhellermann

Description

@jakobhellermann

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.

Details

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions