mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 23:25:03 +00:00
Add Test for new item resolution
This commit is contained in:
parent
b72074a715
commit
d6e6a98c03
2 changed files with 55 additions and 2 deletions
|
@ -7,6 +7,7 @@ use std::sync::Arc;
|
||||||
use ra_db::SourceDatabase;
|
use ra_db::SourceDatabase;
|
||||||
use test_utils::covers;
|
use test_utils::covers;
|
||||||
use insta::assert_snapshot_matches;
|
use insta::assert_snapshot_matches;
|
||||||
|
use either::Either;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Crate,
|
Crate,
|
||||||
|
@ -35,10 +36,22 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
|
||||||
*buf += path;
|
*buf += path;
|
||||||
*buf += "\n";
|
*buf += "\n";
|
||||||
|
|
||||||
let mut entries = map.modules[module].scope.items.iter().collect::<Vec<_>>();
|
let items =
|
||||||
|
map.modules[module].scope.items.iter().map(|(name, it)| (name, Either::Left(it)));
|
||||||
|
let macros =
|
||||||
|
map.modules[module].scope.macros.iter().map(|(name, m)| (name, Either::Right(m)));
|
||||||
|
let mut entries = items.chain(macros).collect::<Vec<_>>();
|
||||||
|
|
||||||
entries.sort_by_key(|(name, _)| *name);
|
entries.sort_by_key(|(name, _)| *name);
|
||||||
for (name, res) in entries {
|
for (name, res) in entries {
|
||||||
*buf += &format!("{}: {}\n", name, dump_resolution(res))
|
match res {
|
||||||
|
Either::Left(it) => {
|
||||||
|
*buf += &format!("{}: {}\n", name, dump_resolution(it));
|
||||||
|
}
|
||||||
|
Either::Right(_) => {
|
||||||
|
*buf += &format!("{}: m\n", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (name, child) in map.modules[module].children.iter() {
|
for (name, child) in map.modules[module].children.iter() {
|
||||||
let path = path.to_string() + &format!("::{}", name);
|
let path = path.to_string() + &format!("::{}", name);
|
||||||
|
|
|
@ -92,3 +92,43 @@ fn macro_rules_from_other_crates_are_visible() {
|
||||||
⋮bar: t
|
⋮bar: t
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
|
||||||
|
let map = def_map_with_crate_graph(
|
||||||
|
"
|
||||||
|
//- /main.rs
|
||||||
|
macro_rules! baz {
|
||||||
|
() => {
|
||||||
|
use foo::bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foo!();
|
||||||
|
bar!();
|
||||||
|
baz!();
|
||||||
|
|
||||||
|
//- /lib.rs
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! foo {
|
||||||
|
() => {
|
||||||
|
struct Foo { field: u32 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! bar {
|
||||||
|
() => {
|
||||||
|
use foo::foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
crate_graph! {
|
||||||
|
"main": ("/main.rs", ["foo"]),
|
||||||
|
"foo": ("/lib.rs", []),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert_snapshot_matches!(map, @r###"crate
|
||||||
|
Foo: t v
|
||||||
|
bar: m
|
||||||
|
foo: m"###);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue