Skip to content

Commit

Permalink
fix(snap): Don't trim unindented snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 13, 2024
1 parent 42e5468 commit b3ca3cd
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions crates/snapbox/src/data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,20 @@ impl Inline {
}

fn trimmed(&self) -> String {
if !self.data.contains('\n') {
return self.data.to_string();
let mut data = self.data;
if data.contains('\n') {
if data.starts_with('\n') {
data = &data[1..]
}
if self.indent {
return trim_indent(data);
}
}
trim_indent(self.data)
data.to_owned()
}
}

fn trim_indent(mut text: &str) -> String {
if text.starts_with('\n') {
text = &text[1..];
}
fn trim_indent(text: &str) -> String {
let indent = text
.lines()
.filter(|it| !it.trim().is_empty())
Expand Down

0 comments on commit b3ca3cd

Please sign in to comment.