diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index c2cb82b..1aab628 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -1400,9 +1400,7 @@ fn format_body( } }) .sum(); - if line.chars().any(|c| !c.is_whitespace()) { - whitespace_margin = min(whitespace_margin, leading_whitespace); - } + whitespace_margin = min(whitespace_margin, leading_whitespace); max_line_len = max(max_line_len, line_length); let line_start_index = line_range.0; diff --git a/tests/formatter.rs b/tests/formatter.rs index 6faab76..0c5a363 100644 --- a/tests/formatter.rs +++ b/tests/formatter.rs @@ -955,3 +955,29 @@ error: title let renderer = Renderer::plain(); assert_data_eq!(renderer.render(input).to_string(), expected); } + +// This tests that reasonable rendering is done in an odd case: when the source +// is a single ASCII whitespace and there's annotation pointing to immediately +// after it. +// +// Previously, this would end up with a `...` rendered instead of just the +// space itself. The `...` seems incorrect here because I don't believe any +// trimming occurs (or is needed). +#[test] +fn one_space_annotation() { + let source = " "; + let input = Level::Error.title("title").snippet( + Snippet::source(source) + .fold(false) + .annotation(Level::Error.span(1..1).label("annotation")), + ); + let expected = "\ +error: title + | +1 |\x20\x20 + | ^ annotation + |\ +"; + let renderer = Renderer::plain(); + assert_data_eq!(renderer.render(input).to_string(), expected); +}