Skip to content

Numerous needless hashes are wrapping the snapshot string #600

@nyurik

Description

@nyurik

What happened?

If a string contains an character that requires escaping in a non-raw literal, the number of hashes is incorrect. This is especially noticeable when validating markdown generation.

Reproduction steps

// No newlines, a single `\` (escaped)
let value = "abc \\######### xyz";
assert_snapshot!(value, @r##########"abc \######### xyz"##########);

// Same number of hashes, only this time there is no escapable symbols
let value = "abc ######### xyz";
assert_snapshot!(value, @"abc ######### xyz");

// A single newline
let value = "abc \n######### xyz";
assert_snapshot!(value, @r##########"
abc 
######### xyz
"##########);

// Copy of the previous test - note that newline is inserted before and after, plus indentation. I assume this is by design?
let value = "
abc
######### xyz
";
assert_snapshot!(value, @r##########"

    abc
    ######### xyz
    
"##########);

Insta Version

1.40.0

rustc Version

1.81.0

What did you expect?

There should be as many hash characters as really needed.

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