rendering bug on small spans in large spans

This commit is contained in:
jdonszelmann 2023-11-08 22:21:04 +01:00
parent a8b4ae012a
commit 2266e73952
No known key found for this signature in database
GPG Key ID: E0C1EA36407B2FF2
1 changed files with 46 additions and 0 deletions

View File

@ -67,6 +67,52 @@ fn empty_source() -> Result<(), MietteError> {
Ok(())
}
#[test]
fn multiple_spans_multiline() {
#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(severity(Error))]
struct MyBad {
#[source_code]
src: NamedSource,
#[label("big")]
big: SourceSpan,
#[label("small")]
small: SourceSpan,
}
let err = MyBad {
src: NamedSource::new(
"issue",
"\
if true {
a
} else {
b
}",
),
big: (0, 32).into(),
small: (14, 1).into(),
};
let out = fmt_report(err.into());
println!("Error: {}", out);
let expected = r#" × oops!
[issue:1:1]
1 if true {
2 a
·
· small
3 } else {
4 b
5 }
· big
"#
.to_string();
assert_eq!(expected, out);
}
#[test]
fn single_line_highlight_span_full_line() {
#[derive(Error, Debug, Diagnostic)]