Add Test for new item resolution
This commit is contained in:
parent
b72074a715
commit
d6e6a98c03
@ -7,6 +7,7 @@
|
||||
use ra_db::SourceDatabase;
|
||||
use test_utils::covers;
|
||||
use insta::assert_snapshot_matches;
|
||||
use either::Either;
|
||||
|
||||
use crate::{
|
||||
Crate,
|
||||
@ -35,10 +36,22 @@ fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) {
|
||||
*buf += path;
|
||||
*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);
|
||||
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() {
|
||||
let path = path.to_string() + &format!("::{}", name);
|
||||
|
@ -92,3 +92,43 @@ macro_rules! structs {
|
||||
⋮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…
Reference in New Issue
Block a user