fix: handle aliased pattern and simplify testcase

This commit is contained in:
Khanh Duong Quoc 2024-10-24 20:17:24 +09:00
parent cf5f1e8620
commit 962d340460
No known key found for this signature in database
GPG key ID: 68399C39885161F3
2 changed files with 32 additions and 23 deletions

View file

@ -294,7 +294,7 @@ pub(crate) fn render_resolution_with_import_pat(
import_edit: LocatedImport,
) -> Option<Builder> {
let resolution = ScopeDef::from(import_edit.original_item);
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
let local_name = get_import_name(resolution, &ctx, &import_edit)?;
Some(render_resolution_pat(ctx, pattern_ctx, local_name, Some(import_edit), resolution))
}

View file

@ -1671,43 +1671,52 @@ mod module {
}
#[test]
fn re_export_aliased_function() {
fn re_export_aliased() {
check(
r#"
//- /lib.rs crate:bar
pub fn func(_: i32) -> i32 {}
//- /lib.rs crate:foo deps:bar
pub use bar::func as my_func;
//- /main.rs crate:main deps:foo
fn main() {
m$0
mod outer {
mod inner {
pub struct BarStruct;
pub fn bar_fun() {}
pub mod bar {}
}
pub use inner::bar as foo;
pub use inner::bar_fun as foo_fun;
pub use inner::BarStruct as FooStruct;
}
fn function() {
foo$0
}
"#,
expect![[r#"
fn my_func() (use foo::my_func) fn(i32) -> i32
st FooStruct (use outer::FooStruct) BarStruct
md foo (use outer::foo)
fn foo_fun() (use outer::foo_fun) fn()
"#]],
);
}
#[test]
fn re_export_aliased_module() {
fn re_export_aliased_pattern() {
check(
r#"
//- /lib.rs crate:bar
pub mod baz {}
//- /lib.rs crate:foo deps:bar
pub use bar::baz as my_baz;
//- /main.rs crate:main deps:foo
fn main() {
m$0
mod outer {
mod inner {
pub struct BarStruct;
pub fn bar_fun() {}
pub mod bar {}
}
pub use inner::bar as foo;
pub use inner::bar_fun as foo_fun;
pub use inner::BarStruct as FooStruct;
}
fn function() {
let foo$0
}
"#,
expect![[r#"
md my_baz (use foo::my_baz)
st FooStruct (use outer::FooStruct)
md foo (use outer::foo)
"#]],
);
}