Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-ssr/src/tests.rs')
-rw-r--r--crates/ide-ssr/src/tests.rs52
1 files changed, 39 insertions, 13 deletions
diff --git a/crates/ide-ssr/src/tests.rs b/crates/ide-ssr/src/tests.rs
index d783e19525..46b633b8a3 100644
--- a/crates/ide-ssr/src/tests.rs
+++ b/crates/ide-ssr/src/tests.rs
@@ -1,8 +1,8 @@
-use expect_test::{expect, Expect};
+use expect_test::{Expect, expect};
use hir::{FilePosition, FileRange};
use ide_db::{
- base_db::{ra_salsa::Durability, SourceDatabase},
EditionedFileId, FxHashSet,
+ base_db::{SourceDatabase, salsa::Durability},
};
use test_utils::RangeOrOffset;
use triomphe::Arc;
@@ -67,7 +67,7 @@ fn parser_undefined_placeholder_in_replacement() {
/// the start of the file. If there's a second cursor marker, then we'll return a single range.
pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec<FileRange>) {
use ide_db::symbol_index::SymbolsDatabase;
- use test_fixture::{WithFixture, WORKSPACE};
+ use test_fixture::{WORKSPACE, WithFixture};
let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) {
ide_db::RootDatabase::with_range_or_offset(code)
} else {
@@ -98,10 +98,18 @@ fn assert_ssr_transform(rule: &str, input: &str, expected: Expect) {
fn assert_ssr_transforms(rules: &[&str], input: &str, expected: Expect) {
let (db, position, selections) = single_file(input);
+ let position =
+ ide_db::FilePosition { file_id: position.file_id.file_id(&db), offset: position.offset };
let mut match_finder = MatchFinder::in_context(
&db,
- position.into(),
- selections.into_iter().map(Into::into).collect(),
+ position,
+ selections
+ .into_iter()
+ .map(|selection| ide_db::FileRange {
+ file_id: selection.file_id.file_id(&db),
+ range: selection.range,
+ })
+ .collect(),
)
.unwrap();
for rule in rules {
@@ -114,8 +122,8 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, expected: Expect) {
}
// Note, db.file_text is not necessarily the same as `input`, since fixture parsing alters
// stuff.
- let mut actual = db.file_text(position.file_id.into()).to_string();
- edits[&position.file_id.into()].apply(&mut actual);
+ let mut actual = db.file_text(position.file_id).text(&db).to_string();
+ edits[&position.file_id].apply(&mut actual);
expected.assert_eq(&actual);
}
@@ -136,8 +144,14 @@ fn assert_matches(pattern: &str, code: &str, expected: &[&str]) {
let (db, position, selections) = single_file(code);
let mut match_finder = MatchFinder::in_context(
&db,
- position.into(),
- selections.into_iter().map(Into::into).collect(),
+ ide_db::FilePosition { file_id: position.file_id.file_id(&db), offset: position.offset },
+ selections
+ .into_iter()
+ .map(|selection| ide_db::FileRange {
+ file_id: selection.file_id.file_id(&db),
+ range: selection.range,
+ })
+ .collect(),
)
.unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();
@@ -153,8 +167,14 @@ fn assert_no_match(pattern: &str, code: &str) {
let (db, position, selections) = single_file(code);
let mut match_finder = MatchFinder::in_context(
&db,
- position.into(),
- selections.into_iter().map(Into::into).collect(),
+ ide_db::FilePosition { file_id: position.file_id.file_id(&db), offset: position.offset },
+ selections
+ .into_iter()
+ .map(|selection| ide_db::FileRange {
+ file_id: selection.file_id.file_id(&db),
+ range: selection.range,
+ })
+ .collect(),
)
.unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();
@@ -169,8 +189,14 @@ fn assert_match_failure_reason(pattern: &str, code: &str, snippet: &str, expecte
let (db, position, selections) = single_file(code);
let mut match_finder = MatchFinder::in_context(
&db,
- position.into(),
- selections.into_iter().map(Into::into).collect(),
+ ide_db::FilePosition { file_id: position.file_id.file_id(&db), offset: position.offset },
+ selections
+ .into_iter()
+ .map(|selection| ide_db::FileRange {
+ file_id: selection.file_id.file_id(&db),
+ range: selection.range,
+ })
+ .collect(),
)
.unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();