Skip to content

Commit 13025ae

Browse files
bors[bot]matklad
andauthored
Merge #6676
6676: Minor cleanup r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents ac30710 + 8c3472b commit 13025ae

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

crates/assists/src/handlers/ignore_test.rs renamed to crates/assists/src/handlers/toggle_ignore.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::{
55

66
use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, Assists};
77

8-
// Assist: ignore_test
8+
// Assist: toggle_ignore
99
//
1010
// Adds `#[ignore]` attribute to the test.
1111
//
@@ -23,20 +23,20 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind,
2323
// assert_eq!(2 + 2, 5);
2424
// }
2525
// ```
26-
pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26+
pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
2727
let attr: ast::Attr = ctx.find_node_at_offset()?;
2828
let func = attr.syntax().parent().and_then(ast::Fn::cast)?;
2929
let attr = test_related_attribute(&func)?;
3030

3131
match has_ignore_attribute(&func) {
3232
None => acc.add(
33-
AssistId("ignore_test", AssistKind::None),
33+
AssistId("toggle_ignore", AssistKind::None),
3434
"Ignore this test",
3535
attr.syntax().text_range(),
3636
|builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")),
3737
),
3838
Some(ignore_attr) => acc.add(
39-
AssistId("unignore_test", AssistKind::None),
39+
AssistId("toggle_ignore", AssistKind::None),
4040
"Re-enable this test",
4141
ignore_attr.syntax().text_range(),
4242
|builder| {
@@ -55,24 +55,19 @@ pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
5555
}
5656

5757
fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
58-
fn_def.attrs().find_map(|attr| {
59-
if attr.path()?.syntax().text() == "ignore" {
60-
Some(attr)
61-
} else {
62-
None
63-
}
64-
})
58+
fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
6559
}
6660

6761
#[cfg(test)]
6862
mod tests {
69-
use super::ignore_test;
7063
use crate::tests::check_assist;
7164

65+
use super::*;
66+
7267
#[test]
7368
fn test_base_case() {
7469
check_assist(
75-
ignore_test,
70+
toggle_ignore,
7671
r#"
7772
#[test<|>]
7873
fn test() {}
@@ -88,7 +83,7 @@ mod tests {
8883
#[test]
8984
fn test_unignore() {
9085
check_assist(
91-
ignore_test,
86+
toggle_ignore,
9287
r#"
9388
#[test<|>]
9489
#[ignore]

crates/assists/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ mod handlers {
141141
mod generate_function;
142142
mod generate_impl;
143143
mod generate_new;
144-
mod ignore_test;
145144
mod infer_function_return_type;
146145
mod inline_local_variable;
147146
mod introduce_named_lifetime;
@@ -164,6 +163,7 @@ mod handlers {
164163
mod replace_string_with_char;
165164
mod replace_unwrap_with_match;
166165
mod split_import;
166+
mod toggle_ignore;
167167
mod unwrap_block;
168168
mod wrap_return_type_in_result;
169169

@@ -190,7 +190,6 @@ mod handlers {
190190
generate_function::generate_function,
191191
generate_impl::generate_impl,
192192
generate_new::generate_new,
193-
ignore_test::ignore_test,
194193
infer_function_return_type::infer_function_return_type,
195194
inline_local_variable::inline_local_variable,
196195
introduce_named_lifetime::introduce_named_lifetime,
@@ -215,6 +214,7 @@ mod handlers {
215214
replace_qualified_name_with_use::replace_qualified_name_with_use,
216215
replace_unwrap_with_match::replace_unwrap_with_match,
217216
split_import::split_import,
217+
toggle_ignore::toggle_ignore,
218218
unwrap_block::unwrap_block,
219219
wrap_return_type_in_result::wrap_return_type_in_result,
220220
// These are manually sorted for better priorities

crates/assists/src/tests/generated.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -473,26 +473,6 @@ impl<T: Clone> Ctx<T> {
473473
)
474474
}
475475

476-
#[test]
477-
fn doctest_ignore_test() {
478-
check_doc_test(
479-
"ignore_test",
480-
r#####"
481-
<|>#[test]
482-
fn arithmetics {
483-
assert_eq!(2 + 2, 5);
484-
}
485-
"#####,
486-
r#####"
487-
#[test]
488-
#[ignore]
489-
fn arithmetics {
490-
assert_eq!(2 + 2, 5);
491-
}
492-
"#####,
493-
)
494-
}
495-
496476
#[test]
497477
fn doctest_infer_function_return_type() {
498478
check_doc_test(
@@ -978,6 +958,26 @@ use std::{collections::HashMap};
978958
)
979959
}
980960

961+
#[test]
962+
fn doctest_toggle_ignore() {
963+
check_doc_test(
964+
"toggle_ignore",
965+
r#####"
966+
<|>#[test]
967+
fn arithmetics {
968+
assert_eq!(2 + 2, 5);
969+
}
970+
"#####,
971+
r#####"
972+
#[test]
973+
#[ignore]
974+
fn arithmetics {
975+
assert_eq!(2 + 2, 5);
976+
}
977+
"#####,
978+
)
979+
}
980+
981981
#[test]
982982
fn doctest_unwrap_block() {
983983
check_doc_test(

0 commit comments

Comments
 (0)