Skip to content

Commit

Permalink
Ignore leading newlines on snapshot comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 19, 2024
1 parent 181dfaf commit f356b52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,13 @@ impl From<SnapshotContents> for String {

impl PartialEq for SnapshotContents {
fn eq(&self, other: &Self) -> bool {
self.0.trim_end() == other.0.trim_end()
self.0
.trim_start_matches(|x| x == '\r' || x == '\n')
.trim_end()
== other
.0
.trim_start_matches(|x| x == '\r' || x == '\n')
.trim_end()
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/test_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,15 @@ fn test_inline_test_in_loop() {
assert_snapshot!(i.to_string(), @"0");
}
}

#[test]
fn test_inline_snapshot_whitespace() {
assert_snapshot!("\n\nfoo\n\n bar\n\n", @r###"
foo
bar
"###);
}

0 comments on commit f356b52

Please sign in to comment.