Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/tests.rs')
| -rw-r--r-- | crates/ide-assists/src/tests.rs | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 95b9eb5294..573d69b5c6 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -50,6 +50,21 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig { assist_emit_must_use: false, }; +pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig { + snippet_cap: SnippetCap::new(true), + allowed: None, + insert_use: InsertUseConfig { + granularity: ImportGranularity::One, + prefix_kind: hir::PrefixKind::Plain, + enforce_granularity: true, + group: true, + skip_glob_imports: true, + }, + prefer_no_std: false, + prefer_prelude: true, + assist_emit_must_use: false, +}; + pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { RootDatabase::with_single_file(text) } @@ -76,6 +91,22 @@ pub(crate) fn check_assist_no_snippet_cap( ); } +#[track_caller] +pub(crate) fn check_assist_import_one( + assist: Handler, + ra_fixture_before: &str, + ra_fixture_after: &str, +) { + let ra_fixture_after = trim_indent(ra_fixture_after); + check_with_config( + TEST_CONFIG_IMPORT_ONE, + assist, + ra_fixture_before, + ExpectedResult::After(&ra_fixture_after), + None, + ); +} + // There is no way to choose what assist within a group you want to test against, // so this is here to allow you choose. pub(crate) fn check_assist_by_label( @@ -106,6 +137,17 @@ pub(crate) fn check_assist_not_applicable_by_label(assist: Handler, ra_fixture: check(assist, ra_fixture, ExpectedResult::NotApplicable, Some(label)); } +#[track_caller] +pub(crate) fn check_assist_not_applicable_for_import_one(assist: Handler, ra_fixture: &str) { + check_with_config( + TEST_CONFIG_IMPORT_ONE, + assist, + ra_fixture, + ExpectedResult::NotApplicable, + None, + ); +} + /// Check assist in unresolved state. Useful to check assists for lazy computation. #[track_caller] pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) { @@ -201,7 +243,7 @@ fn check_with_config( .filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty()) .expect("Assist did not contain any source changes"); let skip_header = source_change.source_file_edits.len() == 1 - && source_change.file_system_edits.len() == 0; + && source_change.file_system_edits.is_empty(); let mut buf = String::new(); for (file_id, (edit, snippet_edit)) in source_change.source_file_edits { |