mitsuhiko / insta

A snapshot testing library for rust
https://insta.rs
Apache License 2.0
2.18k stars 98 forks source link

Trailing whitespace in testcases is ignored for diffs #384

Open TheNeikos opened 1 year ago

TheNeikos commented 1 year ago

What happened?

I created test snapshots with excessive newlines. This was then corrected later, but there was no error or reported diff due to the now missing newlines at the end.

Reproduction steps

  1. assert a snapshot with a lot of newlines at the end
  2. update the value and remove the newlines
  3. no error/diff is reported

Insta Version

1.29

rustc Version

1.70

What did you expect?

I expected newlines changes to be reported, as this is for a CLI application, the trailing whitespaces are important.

mitsuhiko commented 1 year ago

That's unfortunately a limitation. I think one way to work with this would be to have users that need whitespace handling to add markers around it that make this more explicit.

TheNeikos commented 1 year ago

Why is it a Limitation if you don’t mind me asking?

mitsuhiko commented 1 year ago

@TheNeikos it's a natural effect of how the indentation clean up system functions.

TheNeikos commented 1 year ago

@TheNeikos it's a natural effect of how the indentation clean up system functions.

Hm, since the newlines in this case are trailing, why would indentation (which usually comes before non-whitespace characters) interact with those?

mitsuhiko commented 1 year ago

The code that cleans up indentation cannot disambiguate these cases.