mirror of https://github.com/zkat/miette.git
tests: more testing
This commit is contained in:
parent
2cff68449c
commit
3a901ace68
|
|
@ -269,6 +269,53 @@ fn single_line_highlight_at_line_start() -> Result<(), MietteError> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_same_line_highlights() -> Result<(), MietteError> {
|
fn multiple_same_line_highlights() -> 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 = "x"]
|
||||||
|
highlight1: SourceSpan,
|
||||||
|
#[label = "y"]
|
||||||
|
highlight2: SourceSpan,
|
||||||
|
#[label = "z"]
|
||||||
|
highlight3: SourceSpan,
|
||||||
|
}
|
||||||
|
|
||||||
|
let src = "source\n text text text text text\n here".to_string();
|
||||||
|
let err = MyBad {
|
||||||
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
|
highlight1: (9, 4).into(),
|
||||||
|
highlight2: (14, 4).into(),
|
||||||
|
highlight3: (24, 4).into(),
|
||||||
|
};
|
||||||
|
let out = fmt_report(err.into());
|
||||||
|
println!("Error: {}", out);
|
||||||
|
let expected = r#"
|
||||||
|
────[oops::my::bad]──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
× oops!
|
||||||
|
|
||||||
|
╭───[bad_file.rs:1:1] This is the part that broke:
|
||||||
|
1 │ source
|
||||||
|
2 │ text text text text text
|
||||||
|
· ──┬─ ──┬─
|
||||||
|
· ╰── this bit here
|
||||||
|
· ╰── also this bit
|
||||||
|
3 │ here
|
||||||
|
╰───
|
||||||
|
|
||||||
|
‽ try doing it better next time?
|
||||||
|
"#
|
||||||
|
.trim_start()
|
||||||
|
.to_string();
|
||||||
|
assert_eq!(expected, out);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multiple_same_line_highlights_overlapping() -> Result<(), MietteError> {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
|
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
|
||||||
|
|
@ -285,7 +332,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> {
|
||||||
let err = MyBad {
|
let err = MyBad {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight1: (9, 4).into(),
|
highlight1: (9, 4).into(),
|
||||||
highlight2: (14, 4).into(),
|
highlight2: (12, 6).into(),
|
||||||
};
|
};
|
||||||
let out = fmt_report(err.into());
|
let out = fmt_report(err.into());
|
||||||
println!("Error: {}", out);
|
println!("Error: {}", out);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue