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.rs121
1 files changed, 71 insertions, 50 deletions
diff --git a/crates/ide-ssr/src/tests.rs b/crates/ide-ssr/src/tests.rs
index e608b0a7c4..4477a268b2 100644
--- a/crates/ide-ssr/src/tests.rs
+++ b/crates/ide-ssr/src/tests.rs
@@ -1,7 +1,8 @@
use expect_test::{expect, Expect};
+use hir::{FilePosition, FileRange};
use ide_db::{
- base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt},
- FxHashSet,
+ base_db::{salsa::Durability, SourceDatabaseExt},
+ EditionedFileId, FxHashSet,
};
use test_utils::RangeOrOffset;
use triomphe::Arc;
@@ -97,7 +98,12 @@ 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 mut match_finder = MatchFinder::in_context(&db, position, selections).unwrap();
+ let mut match_finder = MatchFinder::in_context(
+ &db,
+ position.into(),
+ selections.into_iter().map(Into::into).collect(),
+ )
+ .unwrap();
for rule in rules {
let rule: SsrRule = rule.parse().unwrap();
match_finder.add_rule(rule).unwrap();
@@ -108,13 +114,13 @@ 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).to_string();
- edits[&position.file_id].apply(&mut actual);
+ let mut actual = db.file_text(position.file_id.into()).to_string();
+ edits[&position.file_id.into()].apply(&mut actual);
expected.assert_eq(&actual);
}
#[allow(clippy::print_stdout)]
-fn print_match_debug_info(match_finder: &MatchFinder<'_>, file_id: FileId, snippet: &str) {
+fn print_match_debug_info(match_finder: &MatchFinder<'_>, file_id: EditionedFileId, snippet: &str) {
let debug_info = match_finder.debug_where_text_equal(file_id, snippet);
println!(
"Match debug info: {} nodes had text exactly equal to '{}'",
@@ -128,7 +134,12 @@ fn print_match_debug_info(match_finder: &MatchFinder<'_>, file_id: FileId, snipp
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, selections).unwrap();
+ let mut match_finder = MatchFinder::in_context(
+ &db,
+ position.into(),
+ selections.into_iter().map(Into::into).collect(),
+ )
+ .unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();
let matched_strings: Vec<String> =
match_finder.matches().flattened().matches.iter().map(|m| m.matched_text()).collect();
@@ -140,7 +151,12 @@ fn assert_matches(pattern: &str, code: &str, expected: &[&str]) {
fn assert_no_match(pattern: &str, code: &str) {
let (db, position, selections) = single_file(code);
- let mut match_finder = MatchFinder::in_context(&db, position, selections).unwrap();
+ let mut match_finder = MatchFinder::in_context(
+ &db,
+ position.into(),
+ selections.into_iter().map(Into::into).collect(),
+ )
+ .unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();
let matches = match_finder.matches().flattened().matches;
if !matches.is_empty() {
@@ -151,7 +167,12 @@ fn assert_no_match(pattern: &str, code: &str) {
fn assert_match_failure_reason(pattern: &str, code: &str, snippet: &str, expected_reason: &str) {
let (db, position, selections) = single_file(code);
- let mut match_finder = MatchFinder::in_context(&db, position, selections).unwrap();
+ let mut match_finder = MatchFinder::in_context(
+ &db,
+ position.into(),
+ selections.into_iter().map(Into::into).collect(),
+ )
+ .unwrap();
match_finder.add_search_pattern(pattern.parse().unwrap()).unwrap();
let mut reasons = Vec::new();
for d in match_finder.debug_where_text_equal(position.file_id, snippet) {
@@ -452,7 +473,7 @@ fn match_struct_instantiation() {
fn match_path() {
let code = r#"
mod foo {
- pub fn bar() {}
+ pub(crate) fn bar() {}
}
fn f() {foo::bar(42)}"#;
assert_matches("foo::bar", code, &["foo::bar"]);
@@ -471,8 +492,8 @@ fn match_pattern() {
fn match_fully_qualified_fn_path() {
let code = r#"
mod a {
- pub mod b {
- pub fn c(_: i32) {}
+ pub(crate) mod b {
+ pub(crate) fn c(_: i32) {}
}
}
use a::b::c;
@@ -487,8 +508,8 @@ fn match_fully_qualified_fn_path() {
fn match_resolved_type_name() {
let code = r#"
mod m1 {
- pub mod m2 {
- pub trait Foo<T> {}
+ pub(crate) mod m2 {
+ pub(crate) trait Foo<T> {}
}
}
mod m3 {
@@ -508,9 +529,9 @@ fn type_arguments_within_path() {
cov_mark::check!(type_arguments_within_path);
let code = r#"
mod foo {
- pub struct Bar<T> {t: T}
+ pub(crate) struct Bar<T> {t: T}
impl<T> Bar<T> {
- pub fn baz() {}
+ pub(crate) fn baz() {}
}
}
fn f1() {foo::Bar::<i32>::baz();}
@@ -659,9 +680,9 @@ fn replace_associated_trait_default_function_call() {
"Bar2::foo() ==>> Bar2::foo2()",
r#"
trait Foo { fn foo() {} }
- pub struct Bar {}
+ pub(crate) struct Bar {}
impl Foo for Bar {}
- pub struct Bar2 {}
+ pub(crate) struct Bar2 {}
impl Foo for Bar2 {}
impl Bar2 { fn foo2() {} }
fn main() {
@@ -671,9 +692,9 @@ fn replace_associated_trait_default_function_call() {
"#,
expect![[r#"
trait Foo { fn foo() {} }
- pub struct Bar {}
+ pub(crate) struct Bar {}
impl Foo for Bar {}
- pub struct Bar2 {}
+ pub(crate) struct Bar2 {}
impl Foo for Bar2 {}
impl Bar2 { fn foo2() {} }
fn main() {
@@ -691,9 +712,9 @@ fn replace_associated_trait_constant() {
"Bar2::VALUE ==>> Bar2::VALUE_2222",
r#"
trait Foo { const VALUE: i32; const VALUE_2222: i32; }
- pub struct Bar {}
+ pub(crate) struct Bar {}
impl Foo for Bar { const VALUE: i32 = 1; const VALUE_2222: i32 = 2; }
- pub struct Bar2 {}
+ pub(crate) struct Bar2 {}
impl Foo for Bar2 { const VALUE: i32 = 1; const VALUE_2222: i32 = 2; }
impl Bar2 { fn foo2() {} }
fn main() {
@@ -703,9 +724,9 @@ fn replace_associated_trait_constant() {
"#,
expect![[r#"
trait Foo { const VALUE: i32; const VALUE_2222: i32; }
- pub struct Bar {}
+ pub(crate) struct Bar {}
impl Foo for Bar { const VALUE: i32 = 1; const VALUE_2222: i32 = 2; }
- pub struct Bar2 {}
+ pub(crate) struct Bar2 {}
impl Foo for Bar2 { const VALUE: i32 = 1; const VALUE_2222: i32 = 2; }
impl Bar2 { fn foo2() {} }
fn main() {
@@ -726,10 +747,10 @@ fn replace_path_in_different_contexts() {
"c::foo() ==>> c::bar()",
r#"
mod a {
- pub mod b {$0
- pub mod c {
- pub fn foo() {}
- pub fn bar() {}
+ pub(crate) mod b {$0
+ pub(crate) mod c {
+ pub(crate) fn foo() {}
+ pub(crate) fn bar() {}
fn f1() { foo() }
}
fn f2() { c::foo() }
@@ -741,10 +762,10 @@ fn replace_path_in_different_contexts() {
"#,
expect![[r#"
mod a {
- pub mod b {
- pub mod c {
- pub fn foo() {}
- pub fn bar() {}
+ pub(crate) mod b {
+ pub(crate) mod c {
+ pub(crate) fn foo() {}
+ pub(crate) fn bar() {}
fn f1() { bar() }
}
fn f2() { c::bar() }
@@ -763,15 +784,15 @@ fn replace_associated_function_with_generics() {
"c::Foo::<$a>::new() ==>> d::Bar::<$a>::default()",
r#"
mod c {
- pub struct Foo<T> {v: T}
- impl<T> Foo<T> { pub fn new() {} }
+ pub(crate) struct Foo<T> {v: T}
+ impl<T> Foo<T> { pub(crate) fn new() {} }
fn f1() {
Foo::<i32>::new();
}
}
mod d {
- pub struct Bar<T> {v: T}
- impl<T> Bar<T> { pub fn default() {} }
+ pub(crate) struct Bar<T> {v: T}
+ impl<T> Bar<T> { pub(crate) fn default() {} }
fn f1() {
super::c::Foo::<i32>::new();
}
@@ -779,15 +800,15 @@ fn replace_associated_function_with_generics() {
"#,
expect![[r#"
mod c {
- pub struct Foo<T> {v: T}
- impl<T> Foo<T> { pub fn new() {} }
+ pub(crate) struct Foo<T> {v: T}
+ impl<T> Foo<T> { pub(crate) fn new() {} }
fn f1() {
crate::d::Bar::<i32>::default();
}
}
mod d {
- pub struct Bar<T> {v: T}
- impl<T> Bar<T> { pub fn default() {} }
+ pub(crate) struct Bar<T> {v: T}
+ impl<T> Bar<T> { pub(crate) fn default() {} }
fn f1() {
Bar::<i32>::default();
}
@@ -823,9 +844,9 @@ fn f1() -> DynTrait<Vec<Error>> {foo()}
#[test]
fn replace_macro_invocations() {
assert_ssr_transform(
- "try!($a) ==>> $a?",
- "macro_rules! try {() => {}} fn f1() -> Result<(), E> {bar(try!(foo()));}",
- expect![["macro_rules! try {() => {}} fn f1() -> Result<(), E> {bar(foo()?);}"]],
+ "try_!($a) ==>> $a?",
+ "macro_rules! try_ {() => {}} fn f1() -> Result<(), E> {bar(try_!(foo()));}",
+ expect![["macro_rules! try_ {() => {}} fn f1() -> Result<(), E> {bar(foo()?);}"]],
);
// FIXME: Figure out why this doesn't work anymore
// assert_ssr_transform(
@@ -1029,14 +1050,14 @@ fn use_declaration_with_braces() {
assert_ssr_transform(
"foo::bar ==>> foo2::bar2",
r#"
- mod foo { pub fn bar() {} pub fn baz() {} }
- mod foo2 { pub fn bar2() {} }
+ mod foo { pub(crate) fn bar() {} pub(crate) fn baz() {} }
+ mod foo2 { pub(crate) fn bar2() {} }
use foo::{baz, bar};
fn main() { bar() }
"#,
expect![["
- mod foo { pub fn bar() {} pub fn baz() {} }
- mod foo2 { pub fn bar2() {} }
+ mod foo { pub(crate) fn bar() {} pub(crate) fn baz() {} }
+ mod foo2 { pub(crate) fn bar2() {} }
use foo::{baz, bar};
fn main() { foo2::bar2() }
"]],
@@ -1266,9 +1287,9 @@ fn match_trait_method_call() {
// `Bar::foo` and `Bar2::foo` resolve to the same function. Make sure we only match if the type
// matches what's in the pattern. Also checks that we handle autoderef.
let code = r#"
- pub struct Bar {}
- pub struct Bar2 {}
- pub trait Foo {
+ pub(crate) struct Bar {}
+ pub(crate) struct Bar2 {}
+ pub(crate) trait Foo {
fn foo(&self, _: i32) {}
}
impl Foo for Bar {}