Skip to content

Commit

Permalink
tests: more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Sep 22, 2021
1 parent 2cff684 commit 3a901ac
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,53 @@ fn single_line_highlight_at_line_start() -> Result<(), MietteError> {

#[test]
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)]
#[error("oops!")]
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
Expand All @@ -285,7 +332,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> {
let err = MyBad {
src: NamedSource::new("bad_file.rs", src),
highlight1: (9, 4).into(),
highlight2: (14, 4).into(),
highlight2: (12, 6).into(),
};
let out = fmt_report(err.into());
println!("Error: {}", out);
Expand Down

0 comments on commit 3a901ac

Please sign in to comment.