Skip to content

Commit

Permalink
Merge pull request #272 from epage/trail
Browse files Browse the repository at this point in the history
fix(snap)!: Include a trailing newline in snapshots
  • Loading branch information
epage authored Apr 18, 2024
2 parents 79b304a + 7fbcc9c commit cbda979
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/snapbox/src/data/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ fn format_patch(patch: &str) -> String {
buf.push('\n');
}
buf.push_str(patch);
if is_multiline {
buf.push('\n');
}
lit_kind.write_end(&mut buf).unwrap();
if matches!(lit_kind, StrLitKind::Raw(_)) {
buf.push(']');
Expand Down Expand Up @@ -358,7 +361,9 @@ mod tests {
[r#"
hello
world
"#]"##]],
"#]
"##]],
patch,
);

Expand Down Expand Up @@ -394,6 +399,7 @@ Patchwork {
),
],
}
"#]],
patchwork.to_debug(),
);
Expand Down
5 changes: 3 additions & 2 deletions crates/snapbox/src/data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ impl Inline {

fn trimmed(&self) -> String {
let mut data = self.data;
if data.contains('\n') && data.starts_with('\n') {
data = &data[1..]
if data.contains('\n') {
data = data.strip_prefix('\n').unwrap_or(data);
data = data.strip_suffix('\n').unwrap_or(data);
}
data.to_owned()
}
Expand Down
1 change: 1 addition & 0 deletions crates/snapbox/tests/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn smoke_test_indent() {
str![[r#"
line1
line2
"#]],
"\
line1
Expand Down

0 comments on commit cbda979

Please sign in to comment.