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

Enforce starting newlines #563

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
No commit message
max-sixty committed Sep 22, 2024
commit e9b4d634d181d2715475787f8ed2dac967798216
20 changes: 4 additions & 16 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
@@ -574,7 +574,7 @@ impl SnapshotContents {
pub(crate) fn from_inline_literal(contents: &str) -> SnapshotContents {
// If it's a single line string, then we don't do anything.
if contents.trim_end().lines().count() <= 1 {
return SnapshotContents::new(contents.to_string(), SnapshotKind::Inline);
return SnapshotContents::new(contents.trim_end().to_string(), SnapshotKind::Inline);
}

// If it's multiline, we trim the first line, which should be empty.
@@ -729,7 +729,7 @@ fn min_indentation(snapshot: &str) -> usize {
fn normalize_inline(snapshot: &str) -> String {
// If it's a single line string, then we don't do anything.
if snapshot.trim_end().lines().count() <= 1 {
return snapshot.to_string();
return snapshot.trim_end().to_string();
}

let indentation = min_indentation(snapshot);
@@ -802,8 +802,7 @@ fn test_normalize_inline_snapshot() {
a
"
),
" a
"
" a"
);

assert_eq!(normalized_of_literal(""), "");
@@ -828,8 +827,7 @@ c
a
"
),
"a
"
"a"
);

// This is a bit of a weird case, but because it's not a true multiline
@@ -844,16 +842,6 @@ a
" a"
);

assert_eq!(
normalized_of_literal(
"
a
"
),
" a
"
);

// This test will pass but raise a warning, so we comment it out for the moment.
// assert_eq!(
// normalized_of_literal(