diff options
Diffstat (limited to 'crates/ra_assists/src/tests.rs')
-rw-r--r-- | crates/ra_assists/src/tests.rs | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 55576813f..49837d60b 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs | |||
@@ -4,18 +4,18 @@ use hir::Semantics; | |||
4 | use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | 4 | use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::TextRange; | 6 | use ra_syntax::TextRange; |
7 | use test_utils::{ | 7 | use test_utils::{assert_eq_text, extract_offset, extract_range, extract_range_or_offset}; |
8 | assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset, | ||
9 | }; | ||
10 | 8 | ||
11 | use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists}; | 9 | use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists}; |
10 | use stdx::trim_indent; | ||
12 | 11 | ||
13 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { | 12 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { |
14 | RootDatabase::with_single_file(text) | 13 | RootDatabase::with_single_file(text) |
15 | } | 14 | } |
16 | 15 | ||
17 | pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { | 16 | pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { |
18 | check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); | 17 | let ra_fixture_after = trim_indent(ra_fixture_after); |
18 | check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after)); | ||
19 | } | 19 | } |
20 | 20 | ||
21 | // FIXME: instead of having a separate function here, maybe use | 21 | // FIXME: instead of having a separate function here, maybe use |
@@ -65,19 +65,8 @@ enum ExpectedResult<'a> { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | fn check(handler: Handler, before: &str, expected: ExpectedResult) { | 67 | fn check(handler: Handler, before: &str, expected: ExpectedResult) { |
68 | let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { | 68 | let (db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before); |
69 | let (db, position) = RootDatabase::with_position(before); | 69 | let text_without_caret = db.file_text(file_with_caret_id).as_ref().to_owned(); |
70 | ( | ||
71 | db.file_text(position.file_id).as_ref().to_owned(), | ||
72 | position.file_id, | ||
73 | RangeOrOffset::Offset(position.offset), | ||
74 | db, | ||
75 | ) | ||
76 | } else { | ||
77 | let (range_or_offset, text_without_caret) = extract_range_or_offset(before); | ||
78 | let (db, file_id) = with_single_file(&text_without_caret); | ||
79 | (text_without_caret, file_id, range_or_offset, db) | ||
80 | }; | ||
81 | 70 | ||
82 | let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; | 71 | let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; |
83 | 72 | ||