|
| 1 | +use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet}; |
| 2 | + |
| 3 | +use snapbox::{assert_data_eq, file}; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn case() { |
| 7 | + let source = r#" |
| 8 | +[workspace.lints.rust] |
| 9 | +rust_2018_idioms = { level = "warn", priority = -1 } |
| 10 | +unnameable_types = "warn" |
| 11 | +unreachable_pub = "warn" |
| 12 | +unsafe_op_in_unsafe_fn = "warn" |
| 13 | +unused_lifetimes = "warn" |
| 14 | +unused_macro_rules = "warn" |
| 15 | +unused_qualifications = "warn" |
| 16 | +"#; |
| 17 | + |
| 18 | + let input = &[Level::ERROR |
| 19 | + .primary_title("all annotation kinds have a highlighted source") |
| 20 | + .element( |
| 21 | + Snippet::source(source) |
| 22 | + .path("Cargo.toml") |
| 23 | + .annotation( |
| 24 | + AnnotationKind::Primary |
| 25 | + .span(214..235) |
| 26 | + .highlight_source(true), |
| 27 | + ) |
| 28 | + .annotation( |
| 29 | + AnnotationKind::Context |
| 30 | + .span(238..244) |
| 31 | + .highlight_source(true), |
| 32 | + ) |
| 33 | + .annotation(AnnotationKind::Visible.span(2..22).highlight_source(true)), |
| 34 | + )]; |
| 35 | + |
| 36 | + let expected_ascii = file!["highlight_source.ascii.term.svg": TermSvg]; |
| 37 | + let renderer = Renderer::styled(); |
| 38 | + assert_data_eq!(renderer.render(input), expected_ascii); |
| 39 | + |
| 40 | + let expected_unicode = file!["highlight_source.unicode.term.svg": TermSvg]; |
| 41 | + let renderer = renderer.decor_style(DecorStyle::Unicode); |
| 42 | + assert_data_eq!(renderer.render(input), expected_unicode); |
| 43 | +} |
0 commit comments