Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/color/highlight_source.ascii.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions tests/color/highlight_source.rs
Original file line number Diff line number Diff line change
@@ -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);
}
38 changes: 38 additions & 0 deletions tests/color/highlight_source.unicode.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/color/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading