Skip to content

Commit

Permalink
add tests for syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
erratic-pattern committed Nov 9, 2023
1 parent 8c482d9 commit 514d599
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,3 +1249,41 @@ fn primary_label() {

assert_eq!(expected, out);
}

#[test]
#[cfg(feature = "syntect-highlighter")]
fn syntax_highlighter() {
#[derive(Debug, Error, Diagnostic)]
#[error("This is an error")]
#[diagnostic()]
pub struct Test {
#[source_code]
src: NamedSource,
#[label("this is a label")]
src_span: SourceSpan,
}

let err = Test {
src: NamedSource::new(
"hello_world.rs",
"fn main() {\n println!(\"Hello, World!\");\n}\n".to_string(),
),
src_span: (16, 26).into(),
};
let mut out = String::new();
GraphicalReportHandler::new_themed(GraphicalTheme::unicode())
.render_report(&mut out, &err)
.unwrap();
let expected = r#"\
× This is an error
╭─[hello_world.rs:2:5]
1 │ fn main() {
2 │ println!(\"Hello, World!\");
· ─────────────┬────────────
· ╰── this is a label
3 │ }
╰────
"#;
println!("{}", out);
assert_eq!(out, expected)
}

0 comments on commit 514d599

Please sign in to comment.