From d6e6a98c03b1a584ed0829bdda24e2c47a742885 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 26 May 2019 20:11:18 +0800 Subject: Add Test for new item resolution --- crates/ra_hir/src/nameres/tests.rs | 17 +++++++++++-- crates/ra_hir/src/nameres/tests/macros.rs | 40 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 14c8ee50b..ffb627c02 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -7,6 +7,7 @@ use std::sync::Arc; use ra_db::SourceDatabase; use test_utils::covers; use insta::assert_snapshot_matches; +use either::Either; use crate::{ Crate, @@ -35,10 +36,22 @@ fn render_crate_def_map(map: &CrateDefMap) -> String { *buf += path; *buf += "\n"; - let mut entries = map.modules[module].scope.items.iter().collect::>(); + 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::>(); + 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); diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index f7ca380ad..42241aeff 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -92,3 +92,43 @@ fn macro_rules_from_other_crates_are_visible() { â‹®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"###); +} -- cgit v1.2.3