Skip to content

Commit aee65a3

Browse files
committed
test: Add tests for primary selection
1 parent b6ccd6f commit aee65a3

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
2+
3+
use snapbox::{assert_data_eq, file};
4+
5+
#[test]
6+
fn case() {
7+
let file_txt_source = r#"this is from a txt file"#;
8+
9+
let rust_source = r#"fn main() {
10+
let b: &[u8] = include_str!("file.txt");
11+
let s: &str = include_bytes!("file.txt");
12+
}"#;
13+
14+
let input = &[
15+
Group::with_title(Level::ERROR.title("mismatched types").id("E0308"))
16+
.element(
17+
Snippet::source(file_txt_source)
18+
.line_start(3)
19+
.path("$DIR/file.txt")
20+
.annotation(
21+
AnnotationKind::Context
22+
.span(0..23)
23+
.label("the macro expands to this string"),
24+
),
25+
)
26+
.element(
27+
Snippet::source(rust_source)
28+
.path("$DIR/mismatched-types.rs")
29+
.annotation(
30+
AnnotationKind::Context
31+
.span(23..28)
32+
.label("expected due to this"),
33+
)
34+
.annotation(
35+
AnnotationKind::Primary
36+
.span(31..55)
37+
.label("expected `&[u8]`, found `&str`"),
38+
),
39+
)
40+
.element(
41+
Level::NOTE
42+
.message("expected reference `&[u8]`\n found reference `&'static str`"),
43+
),
44+
];
45+
let expected = file!["first_snippet_is_primary.term.svg"];
46+
let renderer = Renderer::styled();
47+
assert_data_eq!(renderer.render(input), expected);
48+
}
Lines changed: 54 additions & 0 deletions
Loading

tests/color/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod ann_multiline;
44
mod ann_multiline2;
55
mod ann_removed_nl;
66
mod ensure_emoji_highlight_width;
7+
mod first_snippet_is_primary;
78
mod fold_ann_multiline;
89
mod fold_bad_origin_line;
910
mod fold_leading;

0 commit comments

Comments
 (0)