From 2266e739520f3032f0cad03617704a8e1290f010 Mon Sep 17 00:00:00 2001 From: jdonszelmann Date: Wed, 8 Nov 2023 22:21:04 +0100 Subject: [PATCH] rendering bug on small spans in large spans --- tests/graphical.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/graphical.rs b/tests/graphical.rs index 31db4dc..6a47f70 100644 --- a/tests/graphical.rs +++ b/tests/graphical.rs @@ -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)]