| 
 | 1 | +use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};  | 
 | 2 | +use anstyle::{AnsiColor, Effects, Style};  | 
 | 3 | + | 
 | 4 | +use snapbox::{assert_data_eq, file};  | 
 | 5 | + | 
 | 6 | +const MAGENTA: Style = AnsiColor::Magenta.on_default().effects(Effects::BOLD);  | 
 | 7 | +const BOLD: Style = Style::new().effects(Effects::BOLD);  | 
 | 8 | +#[test]  | 
 | 9 | +fn case() {  | 
 | 10 | +    let source = r#"use b::CustomErrorHandler;  | 
 | 11 | +use c::cnb_runtime;  | 
 | 12 | +
  | 
 | 13 | +
  | 
 | 14 | +    cnb_runtime(CustomErrorHandler {});  | 
 | 15 | +"#;  | 
 | 16 | + | 
 | 17 | +    let title_1 = "the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied";  | 
 | 18 | +    let title_2 = format!("{BOLD}there are {BOLD:#}{MAGENTA}multiple different versions{MAGENTA:#}{BOLD} of crate `{BOLD:#}{MAGENTA}c{MAGENTA:#}{BOLD}` in the dependency graph{BOLD:#}");  | 
 | 19 | + | 
 | 20 | +    let label_1 = "the trait `ErrorHandler` is not implemented for `CustomErrorHandler`";  | 
 | 21 | +    let label_2 = "required by a bound introduced by this call";  | 
 | 22 | +    let label_3 = "one version of crate `c` is used here, as a dependency of crate `b`";  | 
 | 23 | +    let label_4 =  | 
 | 24 | +        "one version of crate `c` is used here, as a direct dependency of the current crate";  | 
 | 25 | + | 
 | 26 | +    let input = &[  | 
 | 27 | +        Group::with_title(Level::ERROR.primary_title(title_1).id("E0277")).element(  | 
 | 28 | +            Snippet::source(source)  | 
 | 29 | +                .path("src/main.rs")  | 
 | 30 | +                .annotation(AnnotationKind::Primary.span(65..86).label(label_1))  | 
 | 31 | +                .annotation(AnnotationKind::Context.span(53..64).label(label_2)),  | 
 | 32 | +        ),  | 
 | 33 | +        Group::with_title(Level::HELP.primary_title(title_2)).element(  | 
 | 34 | +            Snippet::source(source)  | 
 | 35 | +                .path("src/main.rs")  | 
 | 36 | +                .annotation(AnnotationKind::Primary.span(4..5).label(label_3))  | 
 | 37 | +                .annotation(AnnotationKind::Primary.span(31..32).label(label_4)),  | 
 | 38 | +        ),  | 
 | 39 | +    ];  | 
 | 40 | +    let expected = file!["styled_title.term.svg"];  | 
 | 41 | +    let renderer = Renderer::styled();  | 
 | 42 | +    assert_data_eq!(renderer.render(input), expected);  | 
 | 43 | +}  | 
0 commit comments