Skip to content

Commit 2915288

Browse files
committed
test: Add a test for styled Title's
1 parent 5a9461e commit 2915288

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

tests/color/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ mod simple;
1616
mod strip_line;
1717
mod strip_line_char;
1818
mod strip_line_non_ws;
19+
mod styled_title;

tests/color/styled_title.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

tests/color/styled_title.term.svg

Lines changed: 55 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)