mirror of https://github.com/zkat/miette.git
Add test for triple label context
This commit is contained in:
parent
0bf3daebc2
commit
36f7f65f87
|
|
@ -1713,3 +1713,50 @@ fn single_line_with_wide_char_unaligned_span_empty() -> Result<(), MietteError>
|
|||
assert_eq!(expected, out);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn triple_adjacent_highlight() -> Result<(), MietteError> {
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
#[error("oops!")]
|
||||
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
|
||||
struct MyBad {
|
||||
#[source_code]
|
||||
src: NamedSource,
|
||||
#[label = "this bit here"]
|
||||
highlight1: SourceSpan,
|
||||
#[label = "also this bit"]
|
||||
highlight2: SourceSpan,
|
||||
#[label = "finally we got"]
|
||||
highlight3: SourceSpan,
|
||||
}
|
||||
|
||||
let src = "source\n text\n here".to_string();
|
||||
let err = MyBad {
|
||||
src: NamedSource::new("bad_file.rs", src),
|
||||
highlight1: (0, 6).into(),
|
||||
highlight2: (9, 4).into(),
|
||||
highlight3: (18, 4).into(),
|
||||
};
|
||||
let out = fmt_report(err.into());
|
||||
println!("Error: {}", out);
|
||||
let expected = "oops::my::bad
|
||||
|
||||
× oops!
|
||||
╭─[bad_file.rs:1:1]
|
||||
1 │ source
|
||||
· ───┬──
|
||||
· ╰── this bit here
|
||||
2 │ text
|
||||
· ──┬─
|
||||
· ╰── also this bit
|
||||
3 │ here
|
||||
· ──┬─
|
||||
· ╰── finally we got
|
||||
╰────
|
||||
help: try doing it better next time?
|
||||
"
|
||||
.trim_start()
|
||||
.to_string();
|
||||
assert_eq!(expected, out);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue