diff options
author | Aleksey Kladov <[email protected]> | 2020-11-09 13:22:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-11-09 13:44:08 +0000 |
commit | 018f826197bfc5b09c2aa2278714aadb7a66879a (patch) | |
tree | 8dccaadbf1fc9e012a4c7b2293adaa778584fe33 /crates/assists | |
parent | e72cd4600e4c9633673998e03ad639c5e674737d (diff) |
Support multi-file assist tests
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 37 | ||||
-rw-r--r-- | crates/assists/src/tests.rs | 25 |
2 files changed, 56 insertions, 6 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 14209b771..58aadcef7 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -345,6 +345,43 @@ fn another_fn() { | |||
345 | ); | 345 | ); |
346 | } | 346 | } |
347 | 347 | ||
348 | #[test] | ||
349 | fn test_several_files() { | ||
350 | check_assist( | ||
351 | extract_struct_from_enum_variant, | ||
352 | r#" | ||
353 | //- /main.rs | ||
354 | enum E { | ||
355 | <|>V(i32, i32) | ||
356 | } | ||
357 | mod foo; | ||
358 | |||
359 | //- /foo.rs | ||
360 | use crate::E; | ||
361 | fn f() { | ||
362 | let e = E::V(9, 2); | ||
363 | } | ||
364 | "#, | ||
365 | r#" | ||
366 | //- /main.rs | ||
367 | struct V(pub i32, pub i32); | ||
368 | |||
369 | enum E { | ||
370 | V(V) | ||
371 | } | ||
372 | mod foo; | ||
373 | |||
374 | //- /foo.rs | ||
375 | use V; | ||
376 | |||
377 | use crate::E; | ||
378 | fn f() { | ||
379 | let e = E::V(V(9, 2)); | ||
380 | } | ||
381 | "#, | ||
382 | ) | ||
383 | } | ||
384 | |||
348 | fn check_not_applicable(ra_fixture: &str) { | 385 | fn check_not_applicable(ra_fixture: &str) { |
349 | let fixture = | 386 | let fixture = |
350 | format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); | 387 | format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); |
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs index 849d85e76..709a34d03 100644 --- a/crates/assists/src/tests.rs +++ b/crates/assists/src/tests.rs | |||
@@ -7,7 +7,7 @@ use syntax::TextRange; | |||
7 | use test_utils::{assert_eq_text, extract_offset, extract_range}; | 7 | use test_utils::{assert_eq_text, extract_offset, extract_range}; |
8 | 8 | ||
9 | use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists}; | 9 | use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists}; |
10 | use stdx::trim_indent; | 10 | use stdx::{format_to, trim_indent}; |
11 | 11 | ||
12 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { | 12 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { |
13 | RootDatabase::with_single_file(text) | 13 | RootDatabase::with_single_file(text) |
@@ -98,11 +98,24 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: | |||
98 | match (assist, expected) { | 98 | match (assist, expected) { |
99 | (Some(assist), ExpectedResult::After(after)) => { | 99 | (Some(assist), ExpectedResult::After(after)) => { |
100 | let mut source_change = assist.source_change; | 100 | let mut source_change = assist.source_change; |
101 | let change = source_change.source_file_edits.pop().unwrap(); | 101 | assert!(!source_change.source_file_edits.is_empty()); |
102 | 102 | let skip_header = source_change.source_file_edits.len() == 1; | |
103 | let mut actual = db.file_text(change.file_id).as_ref().to_owned(); | 103 | source_change.source_file_edits.sort_by_key(|it| it.file_id); |
104 | change.edit.apply(&mut actual); | 104 | |
105 | assert_eq_text!(after, &actual); | 105 | let mut buf = String::new(); |
106 | for source_file_edit in source_change.source_file_edits { | ||
107 | let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned(); | ||
108 | source_file_edit.edit.apply(&mut text); | ||
109 | if !skip_header { | ||
110 | let sr = db.file_source_root(source_file_edit.file_id); | ||
111 | let sr = db.source_root(sr); | ||
112 | let path = sr.path_for_file(&source_file_edit.file_id).unwrap(); | ||
113 | format_to!(buf, "//- {}\n", path) | ||
114 | } | ||
115 | buf.push_str(&text); | ||
116 | } | ||
117 | |||
118 | assert_eq_text!(after, &buf); | ||
106 | } | 119 | } |
107 | (Some(assist), ExpectedResult::Target(target)) => { | 120 | (Some(assist), ExpectedResult::Target(target)) => { |
108 | let range = assist.assist.target; | 121 | let range = assist.assist.target; |