mirror of https://github.com/zkat/miette.git
Add test for non adjacent contexts
This commit is contained in:
parent
5fda9b0e5b
commit
e16326ac58
|
|
@ -1762,3 +1762,46 @@ fn triple_adjacent_highlight() -> Result<(), MietteError> {
|
|||
assert_eq!(expected, &out);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_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,
|
||||
}
|
||||
|
||||
let src = "source\n\n\n\n text here".to_string();
|
||||
let err = MyBad {
|
||||
src: NamedSource::new("bad_file.rs", src),
|
||||
highlight1: (0, 6).into(),
|
||||
highlight2: (12, 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 │
|
||||
╰────
|
||||
╭─[bad_file.rs:5:3]
|
||||
4 │
|
||||
5 │ text here
|
||||
· ──┬─
|
||||
· ╰── also this bit
|
||||
╰────
|
||||
help: try doing it better next time?
|
||||
";
|
||||
assert_eq!(expected, &out);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue