Skip to content

Commit b500cd4

Browse files
committed
test: Add tests for highlight duplicated diff lines
1 parent dab58dd commit b500cd4

7 files changed

+450
-0
lines changed
Lines changed: 62 additions & 0 deletions
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Patch, Renderer, Snippet};
2+
3+
use snapbox::{assert_data_eq, file};
4+
5+
#[test]
6+
fn case() {
7+
// https://github.com/rust-lang/rust/blob/4b94758d2ba7d0ef71ccf5fde29ce4bc5d6fe2a4/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs
8+
9+
let source = r#"struct Thingie;
10+
11+
impl Thingie {
12+
pub(crate) fn new(
13+
_a: String,
14+
_b: String,
15+
_c: String,
16+
_d: String,
17+
_e: String,
18+
_f: String,
19+
) -> Self {
20+
unimplemented!()
21+
}
22+
}
23+
24+
fn main() {
25+
let foo = Thingie::new(
26+
String::from(""),
27+
String::from(""),
28+
String::from(""),
29+
String::from(""),
30+
String::from(""),
31+
String::from(""),
32+
String::from(""),
33+
);
34+
}"#;
35+
36+
let path = "$DIR/wrong-highlight-span-extra-arguments-147070.rs";
37+
38+
let report = &[
39+
Level::ERROR
40+
.primary_title("this function takes 6 arguments but 7 arguments were supplied")
41+
.id("E0061")
42+
.element(
43+
Snippet::source(source)
44+
.path(path)
45+
.annotation(
46+
AnnotationKind::Context
47+
.span(429..445)
48+
.label("unexpected argument #7 of type `String`"),
49+
)
50+
.annotation(AnnotationKind::Primary.span(251..263)),
51+
),
52+
Level::NOTE
53+
.secondary_title("associated function defined here")
54+
.element(
55+
Snippet::source(source)
56+
.path(path)
57+
.annotation(AnnotationKind::Primary.span(50..53)),
58+
),
59+
Level::HELP
60+
.secondary_title("remove the extra argument")
61+
.element(
62+
Snippet::source(source)
63+
.path(path)
64+
.patch(Patch::new(419..445, "")),
65+
),
66+
];
67+
68+
let expected_ascii = file!["highlight_duplicated_diff_lines.ascii.term.svg": TermSvg];
69+
let renderer = Renderer::styled();
70+
assert_data_eq!(renderer.render(report), expected_ascii);
71+
72+
let expected_unicode = file!["highlight_duplicated_diff_lines.unicode.term.svg": TermSvg];
73+
let renderer = renderer.decor_style(DecorStyle::Unicode);
74+
assert_data_eq!(renderer.render(report), expected_unicode);
75+
}
Lines changed: 62 additions & 0 deletions
Loading

tests/color/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ mod fold_ann_multiline;
99
mod fold_bad_origin_line;
1010
mod fold_leading;
1111
mod fold_trailing;
12+
mod highlight_duplicated_diff_lines;
1213
mod highlight_source;
1314
mod issue_9;
1415
mod multiline_removal_suggestion;
1516
mod multiple_annotations;
17+
mod multiple_highlight_duplicated;
1618
mod multiple_multiline_removal;
1719
mod primary_title_second_group;
1820
mod simple;
Lines changed: 78 additions & 0 deletions
Loading
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Patch, Renderer, Snippet};
2+
3+
use snapbox::{assert_data_eq, file};
4+
5+
#[test]
6+
fn case() {
7+
let source = r#"struct Thingie;
8+
9+
impl Thingie {
10+
pub(crate) fn new(
11+
_a: String,
12+
_b: String,
13+
_c: String,
14+
_d: String,
15+
_e: String,
16+
_f: String,
17+
) -> Self {
18+
unimplemented!()
19+
}
20+
}
21+
22+
fn main() {
23+
let foo = Thingie::new(
24+
String::from(""),
25+
String::from(""),
26+
String::from(""),
27+
String::from(""),
28+
String::from(""),
29+
String::from(""),
30+
String::from(""),
31+
);
32+
}"#;
33+
34+
let path = "$DIR/wrong-highlight-span-extra-arguments-147070.rs";
35+
36+
let report = &[
37+
Level::ERROR
38+
.primary_title("this function takes 6 arguments but 7 arguments were supplied")
39+
.id("E0061")
40+
.element(
41+
Snippet::source(source)
42+
.path(path)
43+
.annotation(
44+
AnnotationKind::Context
45+
.span(429..445)
46+
.label("unexpected argument #7 of type `String`"),
47+
)
48+
.annotation(AnnotationKind::Primary.span(251..263)),
49+
),
50+
Level::NOTE
51+
.secondary_title("associated function defined here")
52+
.element(
53+
Snippet::source(source)
54+
.path(path)
55+
.annotation(AnnotationKind::Primary.span(50..53)),
56+
),
57+
Level::HELP
58+
.secondary_title("remove the extra argument")
59+
.element(
60+
Snippet::source(source)
61+
.path(path)
62+
.patch(Patch::new(419..445, "")),
63+
)
64+
.element(
65+
Snippet::source(source)
66+
.path(path)
67+
.patch(Patch::new(266..292, "")),
68+
)
69+
.element(
70+
Snippet::source(source)
71+
.path(path)
72+
.patch(Patch::new(289..315, "")),
73+
)
74+
.element(
75+
Snippet::source(source)
76+
.path(path)
77+
.patch(Patch::new(403..420, "")),
78+
)
79+
.element(
80+
Snippet::source(source)
81+
.path(path)
82+
.patch(Patch::new(419..445, "")),
83+
),
84+
];
85+
86+
let expected_ascii = file!["multiple_highlight_duplicated.ascii.term.svg": TermSvg];
87+
let renderer = Renderer::styled();
88+
assert_data_eq!(renderer.render(report), expected_ascii);
89+
90+
let expected_unicode = file!["multiple_highlight_duplicated.unicode.term.svg": TermSvg];
91+
let renderer = renderer.decor_style(DecorStyle::Unicode);
92+
assert_data_eq!(renderer.render(report), expected_unicode);
93+
}

0 commit comments

Comments
 (0)