Skip to content

Commit 90f5bb8

Browse files
committed
renderdag: box: render newlines in asserts tests.
1 parent dcfd60d commit 90f5bb8

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

eden/scm/lib/renderdag/src/box_drawing.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,35 @@ mod tests {
345345
}
346346
}
347347

348-
fn render(fixture: &TestFixture, with_branch_pad: BranchPadding) -> String {
348+
/// Type for rendering the graph strings with newlines in asserts.
349+
#[derive(PartialEq, Eq)]
350+
struct GraphString(String);
351+
352+
impl std::fmt::Debug for GraphString {
353+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
354+
write!(f, "{}", self.0.replace("\\n", "\n"))
355+
}
356+
}
357+
358+
impl From<&str> for GraphString {
359+
fn from(value: &str) -> Self {
360+
GraphString(value.to_owned())
361+
}
362+
}
363+
364+
fn render(fixture: &TestFixture, with_branch_pad: BranchPadding) -> GraphString {
349365
let mut renderer = GraphRowRenderer::new().output().build_box_drawing();
350366
if with_branch_pad == BranchPadding::Yes {
351367
renderer = renderer.with_branch_padding();
352368
}
353-
render_string(fixture, &mut renderer)
369+
GraphString(render_string(fixture, &mut renderer))
354370
}
355371

356372
/// Filters the expected graph string according to the options
357373
///
358374
/// If a line ends with ` <branch pad>`, it will only be included if
359375
/// `with_branch_pad` is `Yes`.
360-
fn filter(with_branch_pad: BranchPadding, expected: &str) -> String {
376+
fn filter(with_branch_pad: BranchPadding, expected: &str) -> GraphString {
361377
let mut filtered = String::new();
362378
for mut line in expected.lines() {
363379
if let Some(pad_pos) = line.find(" <branch pad>") {
@@ -372,7 +388,7 @@ mod tests {
372388
if !filtered.is_empty() {
373389
filtered.pop();
374390
}
375-
filtered
391+
GraphString(filtered)
376392
}
377393

378394
#[test]
@@ -696,7 +712,11 @@ mod tests {
696712
if branch_pad == BranchPadding::Yes {
697713
renderer = renderer.with_branch_padding();
698714
}
699-
render_string_with_order(&test_fixtures::ORDERS1, &mut renderer, Some(&order))
715+
GraphString(render_string_with_order(
716+
&test_fixtures::ORDERS1,
717+
&mut renderer,
718+
Some(&order),
719+
))
700720
};
701721

702722
for branch_pad in [BranchPadding::No, BranchPadding::Yes] {

0 commit comments

Comments
 (0)