annotate-snippets-rs icon indicating copy to clipboard operation
annotate-snippets-rs copied to clipboard

Displaying LF in CRLF shows 1:1 in line:col

Open DaniPopes opened this issue 1 year ago • 0 comments

I wrote a test to demonstrate this:

#[test]
fn lf_in_crlf() {
    let source = "a\r\nb";
    let input = Level::Error.title("").snippet(
        Snippet::source(source)
            .origin("file/path")
            .line_start(3)
            .annotation(Level::Error.span(2..3)), // \n
    );
    let expected = str![[r#"
error
 --> file/path:1:1
  |
3 |   a
4 | | b
  | |_^
  |"#]]
    .indent(false);
    let renderer = Renderer::plain().anonymized_line_numbers(false);
    assert_eq(expected, renderer.render(input).to_string());
}

This only happens when a span points to exactly the \n byte that's preceded by \r

I believe this behavior is present since at least 0.10.0

DaniPopes avatar Apr 18 '24 01:04 DaniPopes