diff --git a/tests/color/highlight_source.ascii.term.svg b/tests/color/highlight_source.ascii.term.svg new file mode 100644 index 00000000..da7f88e9 --- /dev/null +++ b/tests/color/highlight_source.ascii.term.svg @@ -0,0 +1,38 @@ + + + + + + + error: all annotation kinds have a highlighted source + + --> Cargo.toml:9:1 + + | + + 2 | [workspace.lints.rust] + + ... + + 9 | unused_qualifications = "warn" + + | ^^^^^^^^^^^^^^^^^^^^^ ------ + + + + diff --git a/tests/color/highlight_source.rs b/tests/color/highlight_source.rs new file mode 100644 index 00000000..44191470 --- /dev/null +++ b/tests/color/highlight_source.rs @@ -0,0 +1,43 @@ +use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet}; + +use snapbox::{assert_data_eq, file}; + +#[test] +fn case() { + let source = r#" +[workspace.lints.rust] +rust_2018_idioms = { level = "warn", priority = -1 } +unnameable_types = "warn" +unreachable_pub = "warn" +unsafe_op_in_unsafe_fn = "warn" +unused_lifetimes = "warn" +unused_macro_rules = "warn" +unused_qualifications = "warn" +"#; + + let input = &[Level::ERROR + .primary_title("all annotation kinds have a highlighted source") + .element( + Snippet::source(source) + .path("Cargo.toml") + .annotation( + AnnotationKind::Primary + .span(214..235) + .highlight_source(true), + ) + .annotation( + AnnotationKind::Context + .span(238..244) + .highlight_source(true), + ) + .annotation(AnnotationKind::Visible.span(2..22).highlight_source(true)), + )]; + + let expected_ascii = file!["highlight_source.ascii.term.svg": TermSvg]; + let renderer = Renderer::styled(); + assert_data_eq!(renderer.render(input), expected_ascii); + + let expected_unicode = file!["highlight_source.unicode.term.svg": TermSvg]; + let renderer = renderer.decor_style(DecorStyle::Unicode); + assert_data_eq!(renderer.render(input), expected_unicode); +} diff --git a/tests/color/highlight_source.unicode.term.svg b/tests/color/highlight_source.unicode.term.svg new file mode 100644 index 00000000..9ab809cc --- /dev/null +++ b/tests/color/highlight_source.unicode.term.svg @@ -0,0 +1,38 @@ + + + + + + + error: all annotation kinds have a highlighted source + + ╭▸ Cargo.toml:9:1 + + + + 2 [workspace.lints.rust] + + + + 9 unused_qualifications = "warn" + + ╰╴━━━━━━━━━━━━━━━━━━━━━ ────── + + + + diff --git a/tests/color/main.rs b/tests/color/main.rs index 4faaf28d..f61e113a 100644 --- a/tests/color/main.rs +++ b/tests/color/main.rs @@ -9,6 +9,7 @@ mod fold_ann_multiline; mod fold_bad_origin_line; mod fold_leading; mod fold_trailing; +mod highlight_source; mod issue_9; mod multiline_removal_suggestion; mod multiple_annotations;