Skip to content

Commit 6a16e22

Browse files
committed
test: Add tests for no folding suggestion
1 parent 7edacbb commit 6a16e22

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

tests/formatter.rs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,3 +4541,160 @@ help: add a `;` here
45414541
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
45424542
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
45434543
}
4544+
4545+
#[test]
4546+
fn suggestion_no_fold() {
4547+
let source = r#"fn main() {
4548+
let variable_name = 42;
4549+
function_with_lots_of_arguments(
4550+
variable_name,
4551+
variable_name,
4552+
variable_name,
4553+
variable_name,
4554+
);
4555+
}"#;
4556+
let path = "$DIR/trimmed_multiline_suggestion.rs";
4557+
4558+
let input = &[
4559+
Group::with_title(
4560+
Level::ERROR
4561+
.primary_title("this function takes 6 arguments but 5 arguments were supplied")
4562+
.id("E0061"),
4563+
)
4564+
.element(
4565+
Snippet::source(source)
4566+
.path(path)
4567+
.annotation(
4568+
AnnotationKind::Context
4569+
.span(108..121)
4570+
.label("argument #2 of type `char` is missing"),
4571+
)
4572+
.annotation(AnnotationKind::Primary.span(44..75)),
4573+
),
4574+
Group::with_title(Level::HELP.secondary_title("provide the argument")).element(
4575+
Snippet::source(source)
4576+
.path(path)
4577+
.fold(false)
4578+
.patch(Patch::new(
4579+
75..174,
4580+
"(
4581+
variable_name,
4582+
/* char */,
4583+
variable_name,
4584+
variable_name,
4585+
variable_name,
4586+
)",
4587+
)),
4588+
),
4589+
];
4590+
4591+
let expected_ascii = str![[r#"
4592+
error[E0061]: this function takes 6 arguments but 5 arguments were supplied
4593+
--> $DIR/trimmed_multiline_suggestion.rs:3:5
4594+
|
4595+
3 | function_with_lots_of_arguments(
4596+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4597+
4 | variable_name,
4598+
5 | variable_name,
4599+
| ------------- argument #2 of type `char` is missing
4600+
|
4601+
help: provide the argument
4602+
|
4603+
3 | function_with_lots_of_arguments(
4604+
4 | variable_name,
4605+
5 ~ /* char */,
4606+
6 ~ variable_name,
4607+
|
4608+
"#]];
4609+
let renderer_ascii = Renderer::plain();
4610+
assert_data_eq!(renderer_ascii.render(input), expected_ascii);
4611+
4612+
let expected_unicode = str![[r#"
4613+
error[E0061]: this function takes 6 arguments but 5 arguments were supplied
4614+
╭▸ $DIR/trimmed_multiline_suggestion.rs:3:5
4615+
4616+
3 │ function_with_lots_of_arguments(
4617+
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4618+
4 │ variable_name,
4619+
5 │ variable_name,
4620+
│ ───────────── argument #2 of type `char` is missing
4621+
╰╴
4622+
help: provide the argument
4623+
╭╴
4624+
3 │ function_with_lots_of_arguments(
4625+
4 │ variable_name,
4626+
5 ± /* char */,
4627+
6 ± variable_name,
4628+
╰╴
4629+
"#]];
4630+
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
4631+
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
4632+
}
4633+
4634+
#[test]
4635+
fn suggestion_no_fold_replacement_ends_with_newline() {
4636+
let source = r#"
4637+
use st::cell::Cell;
4638+
4639+
mod bar {
4640+
pub fn bar() { bar::baz(); }
4641+
4642+
fn baz() {}
4643+
}
4644+
4645+
use bas::bar;
4646+
4647+
struct Foo {
4648+
bar: st::cell::Cell<bool>
4649+
}
4650+
4651+
fn main() {}"#;
4652+
4653+
let input = &[
4654+
Level::ERROR
4655+
.primary_title("failed to resolve: use of undeclared crate or module `st`")
4656+
.id("E0433")
4657+
.element(
4658+
Snippet::source(source).line_start(1).annotation(
4659+
AnnotationKind::Primary
4660+
.span(122..124)
4661+
.label("use of undeclared crate or module `st`"),
4662+
),
4663+
),
4664+
Level::HELP
4665+
.secondary_title("consider importing this module")
4666+
.element(
4667+
Snippet::source(source)
4668+
.fold(false)
4669+
.patch(Patch::new(1..1, "use std::cell;\n")),
4670+
),
4671+
];
4672+
let expected_ascii = str![[r#"
4673+
error[E0433]: failed to resolve: use of undeclared crate or module `st`
4674+
|
4675+
13 | bar: st::cell::Cell<bool>
4676+
| ^^ use of undeclared crate or module `st`
4677+
|
4678+
help: consider importing this module
4679+
|
4680+
2 + use std::cell;
4681+
|
4682+
"#]];
4683+
4684+
let renderer = Renderer::plain();
4685+
assert_data_eq!(renderer.render(input), expected_ascii);
4686+
4687+
let expected_unicode = str![[r#"
4688+
error[E0433]: failed to resolve: use of undeclared crate or module `st`
4689+
╭▸
4690+
13 │ bar: st::cell::Cell<bool>
4691+
│ ━━ use of undeclared crate or module `st`
4692+
╰╴
4693+
help: consider importing this module
4694+
╭╴
4695+
2 + use std::cell;
4696+
╰╴
4697+
"#]];
4698+
let renderer = renderer.decor_style(DecorStyle::Unicode);
4699+
assert_data_eq!(renderer.render(input), expected_unicode);
4700+
}

0 commit comments

Comments
 (0)