Skip to content

Commit d53ce78

Browse files
committed
test: Add tests for trimming multiline suggestions
1 parent 5a632cd commit d53ce78

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

tests/formatter.rs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,3 +4329,215 @@ error: ensure single line at line 0 rendered correctly with group line lined up
43294329
let renderer = renderer.decor_style(DecorStyle::Unicode);
43304330
assert_data_eq!(renderer.render(input), expected_unicode);
43314331
}
4332+
4333+
#[test]
4334+
fn trimmed_multiline_suggestion() {
4335+
let source = r#"fn function_with_lots_of_arguments(a: i32, b: char, c: i32, d: i32, e: i32, f: i32) {}
4336+
4337+
fn main() {
4338+
let variable_name = 42;
4339+
function_with_lots_of_arguments(
4340+
variable_name,
4341+
variable_name,
4342+
variable_name,
4343+
variable_name,
4344+
variable_name,
4345+
);
4346+
//~^^^^^^^ ERROR this function takes 6 arguments but 5 arguments were supplied [E0061]
4347+
}
4348+
"#;
4349+
let path = "$DIR/trimmed_multiline_suggestion.rs";
4350+
4351+
let input = &[
4352+
Group::with_title(
4353+
Level::ERROR
4354+
.primary_title("this function takes 6 arguments but 5 arguments were supplied")
4355+
.id("E0061"),
4356+
)
4357+
.element(
4358+
Snippet::source(source)
4359+
.path(path)
4360+
.annotation(
4361+
AnnotationKind::Context
4362+
.span(196..209)
4363+
.label("argument #2 of type `char` is missing"),
4364+
)
4365+
.annotation(AnnotationKind::Primary.span(132..163)),
4366+
),
4367+
Group::with_title(Level::NOTE.secondary_title("function defined here")).element(
4368+
Snippet::source(source)
4369+
.path(path)
4370+
.annotation(AnnotationKind::Context.span(43..50).label(""))
4371+
.annotation(AnnotationKind::Primary.span(3..34)),
4372+
),
4373+
Group::with_title(Level::HELP.secondary_title("provide the argument")).element(
4374+
Snippet::source(source).path(path).patch(Patch::new(
4375+
163..285,
4376+
"(
4377+
variable_name,
4378+
/* char */,
4379+
variable_name,
4380+
variable_name,
4381+
variable_name,
4382+
variable_name,
4383+
)",
4384+
)),
4385+
),
4386+
];
4387+
4388+
let expected_ascii = str![[r#"
4389+
error[E0061]: this function takes 6 arguments but 5 arguments were supplied
4390+
--> $DIR/trimmed_multiline_suggestion.rs:5:5
4391+
|
4392+
5 | function_with_lots_of_arguments(
4393+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4394+
6 | variable_name,
4395+
7 | variable_name,
4396+
| ------------- argument #2 of type `char` is missing
4397+
|
4398+
note: function defined here
4399+
--> $DIR/trimmed_multiline_suggestion.rs:1:4
4400+
|
4401+
1 | fn function_with_lots_of_arguments(a: i32, b: char, c: i32, d: i32, e: i32, f: i32) {}
4402+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -------
4403+
help: provide the argument
4404+
|
4405+
7 | function_with_lots_of_arguments(
4406+
8 | variable_name,
4407+
9 ~ /* char */,
4408+
10 ~ variable_name,
4409+
|
4410+
"#]];
4411+
let renderer_ascii = Renderer::plain();
4412+
assert_data_eq!(renderer_ascii.render(input), expected_ascii);
4413+
4414+
let expected_unicode = str![[r#"
4415+
error[E0061]: this function takes 6 arguments but 5 arguments were supplied
4416+
╭▸ $DIR/trimmed_multiline_suggestion.rs:5:5
4417+
4418+
5 │ function_with_lots_of_arguments(
4419+
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4420+
6 │ variable_name,
4421+
7 │ variable_name,
4422+
│ ───────────── argument #2 of type `char` is missing
4423+
╰╴
4424+
note: function defined here
4425+
╭▸ $DIR/trimmed_multiline_suggestion.rs:1:4
4426+
4427+
1 │ fn function_with_lots_of_arguments(a: i32, b: char, c: i32, d: i32, e: i32, f: i32) {}
4428+
╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ───────
4429+
help: provide the argument
4430+
╭╴
4431+
7 │ function_with_lots_of_arguments(
4432+
8 │ variable_name,
4433+
9 ± /* char */,
4434+
10 ± variable_name,
4435+
╰╴
4436+
"#]];
4437+
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
4438+
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
4439+
}
4440+
4441+
#[test]
4442+
fn trimmed_multiline_suggestion_elided_lines() {
4443+
let source_0 = r#" nums.iter().for_each(|x| {
4444+
if *x > 0 {
4445+
println!("Positive number");
4446+
} else {
4447+
println!("Negative number");
4448+
}
4449+
})
4450+
"#;
4451+
let source_1 = r#"#![deny(clippy::semicolon_if_nothing_returned)]
4452+
"#;
4453+
4454+
let input = &[
4455+
Group::with_title(Level::ERROR.primary_title(
4456+
"consider adding a `;` to the last statement for consistent formatting",
4457+
))
4458+
.element(
4459+
Snippet::source(source_0)
4460+
.path("tests/ui/semicolon_if_nothing_returned_testing.rs")
4461+
.line_start(4)
4462+
.annotation(AnnotationKind::Primary.span(4..166)),
4463+
),
4464+
Group::with_title(Level::NOTE.secondary_title("the lint level is defined here")).element(
4465+
Snippet::source(source_1)
4466+
.path("tests/ui/semicolon_if_nothing_returned_testing.rs")
4467+
.line_start(2)
4468+
.annotation(AnnotationKind::Primary.span(8..45)),
4469+
),
4470+
Group::with_title(Level::HELP.secondary_title("add a `;` here")).element(
4471+
Snippet::source(source_0)
4472+
.path("tests/ui/semicolon_if_nothing_returned_testing.rs")
4473+
.line_start(4)
4474+
.fold(true)
4475+
.patch(Patch::new(
4476+
4..166,
4477+
r#"nums.iter().for_each(|x| {
4478+
if *x > 0 {
4479+
println!("Positive number");
4480+
} else {
4481+
println!("Negative number");
4482+
}
4483+
});"#,
4484+
)),
4485+
),
4486+
];
4487+
4488+
let expected_ascii = str![[r#"
4489+
error: consider adding a `;` to the last statement for consistent formatting
4490+
--> tests/ui/semicolon_if_nothing_returned_testing.rs:4:5
4491+
|
4492+
4 | / nums.iter().for_each(|x| {
4493+
5 | | if *x > 0 {
4494+
6 | | println!("Positive number");
4495+
7 | | } else {
4496+
... |
4497+
10 | | })
4498+
| |______^
4499+
|
4500+
note: the lint level is defined here
4501+
--> tests/ui/semicolon_if_nothing_returned_testing.rs:2:9
4502+
|
4503+
2 | #![deny(clippy::semicolon_if_nothing_returned)]
4504+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4505+
help: add a `;` here
4506+
|
4507+
10 | nums.iter().for_each(|x| {
4508+
...
4509+
15 | }
4510+
16 ~ });
4511+
|
4512+
"#]];
4513+
let renderer_ascii = Renderer::plain();
4514+
assert_data_eq!(renderer_ascii.render(input), expected_ascii);
4515+
4516+
let expected_unicode = str![[r#"
4517+
error: consider adding a `;` to the last statement for consistent formatting
4518+
╭▸ tests/ui/semicolon_if_nothing_returned_testing.rs:4:5
4519+
4520+
4 │ ┏ nums.iter().for_each(|x| {
4521+
5 │ ┃ if *x > 0 {
4522+
6 │ ┃ println!("Positive number");
4523+
7 │ ┃ } else {
4524+
‡ ┃
4525+
10 │ ┃ })
4526+
│ ┗━━━━━━┛
4527+
╰╴
4528+
note: the lint level is defined here
4529+
╭▸ tests/ui/semicolon_if_nothing_returned_testing.rs:2:9
4530+
4531+
2 │ #![deny(clippy::semicolon_if_nothing_returned)]
4532+
╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4533+
help: add a `;` here
4534+
╭╴
4535+
10 │ nums.iter().for_each(|x| {
4536+
4537+
15 │ }
4538+
16 ± });
4539+
╰╴
4540+
"#]];
4541+
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
4542+
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
4543+
}

0 commit comments

Comments
 (0)