Skip to content

Commit b3ca3cd

Browse files
committed
fix(snap): Don't trim unindented snapshots
1 parent 42e5468 commit b3ca3cd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/snapbox/src/data/source.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ impl Inline {
102102
}
103103

104104
fn trimmed(&self) -> String {
105-
if !self.data.contains('\n') {
106-
return self.data.to_string();
105+
let mut data = self.data;
106+
if data.contains('\n') {
107+
if data.starts_with('\n') {
108+
data = &data[1..]
109+
}
110+
if self.indent {
111+
return trim_indent(data);
112+
}
107113
}
108-
trim_indent(self.data)
114+
data.to_owned()
109115
}
110116
}
111117

112-
fn trim_indent(mut text: &str) -> String {
113-
if text.starts_with('\n') {
114-
text = &text[1..];
115-
}
118+
fn trim_indent(text: &str) -> String {
116119
let indent = text
117120
.lines()
118121
.filter(|it| !it.trim().is_empty())

0 commit comments

Comments
 (0)