From d2d7a4403cad6913a1944cbe4aaedc6c8b936382 Mon Sep 17 00:00:00 2001 From: James Leitch Date: Sun, 1 Nov 2020 17:20:55 -0700 Subject: Test Fixture ExplicitRoot + ModuleResolutionRelativePathOutsideRoot. --- crates/base_db/src/fixture.rs | 4 +++- crates/hir_def/src/nameres/tests/mod_resolution.rs | 17 +++++++++++++++-- crates/test_utils/src/fixture.rs | 4 ++++ 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 66e6443cb..3c6c516b2 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs @@ -150,6 +150,8 @@ impl ChangeFixture { entry.text.clone() }; + let explicit_root = entry.explicit_root; + let meta = FileMeta::from(entry); assert!(meta.path.starts_with(&source_root_prefix)); @@ -169,7 +171,7 @@ impl ChangeFixture { let dep = CrateName::normalize_dashes(&dep); crate_deps.push((crate_name.clone(), dep)) } - } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { + } else if meta.path == "/main.rs" || meta.path == "/lib.rs" || explicit_root { assert!(default_crate_root.is_none()); default_crate_root = Some(file_id); default_cfg = meta.cfg; diff --git a/crates/hir_def/src/nameres/tests/mod_resolution.rs b/crates/hir_def/src/nameres/tests/mod_resolution.rs index f93337a6e..0b2b4429d 100644 --- a/crates/hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/hir_def/src/nameres/tests/mod_resolution.rs @@ -323,13 +323,26 @@ pub struct Baz; fn module_resolution_relative_path_outside_root() { check( r#" -//- /main.rs +//- /a/b/c/d/e/main.rs root: #[path="../../../../../outside.rs"] mod foo; + +//- /outside.rs +mod bar; + +//- /bar.rs +pub struct Baz; "#, expect![[r#" crate - "#]], + foo: t + + crate::foo + bar: t + + crate::foo::bar + Baz: t v +"#]], ); } diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index e40b61a94..806ab06c1 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -8,6 +8,7 @@ use stdx::{lines_with_ends, split_once, trim_indent}; pub struct Fixture { pub path: String, pub text: String, + pub explicit_root: bool, pub krate: Option, pub deps: Vec, pub cfg_atoms: Vec, @@ -64,6 +65,7 @@ impl Fixture { let path = components[0].to_string(); assert!(path.starts_with('/')); + let mut explicit_root = false; let mut krate = None; let mut deps = Vec::new(); let mut edition = None; @@ -73,6 +75,7 @@ impl Fixture { for component in components[1..].iter() { let (key, value) = split_once(component, ':').unwrap(); match key { + "root" => explicit_root = true, "crate" => krate = Some(value.to_string()), "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), "edition" => edition = Some(value.to_string()), @@ -98,6 +101,7 @@ impl Fixture { Fixture { path, text: String::new(), + explicit_root: explicit_root, krate: krate, deps, cfg_atoms, -- cgit v1.2.3 From ff87726074915fe298cb37ca60b193f922a612df Mon Sep 17 00:00:00 2001 From: James Leitch Date: Mon, 2 Nov 2020 10:57:31 -0700 Subject: Feedback. --- crates/base_db/src/fixture.rs | 4 +--- crates/hir_def/src/nameres/tests/mod_resolution.rs | 2 +- crates/test_utils/src/fixture.rs | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 3c6c516b2..66e6443cb 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs @@ -150,8 +150,6 @@ impl ChangeFixture { entry.text.clone() }; - let explicit_root = entry.explicit_root; - let meta = FileMeta::from(entry); assert!(meta.path.starts_with(&source_root_prefix)); @@ -171,7 +169,7 @@ impl ChangeFixture { let dep = CrateName::normalize_dashes(&dep); crate_deps.push((crate_name.clone(), dep)) } - } else if meta.path == "/main.rs" || meta.path == "/lib.rs" || explicit_root { + } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { assert!(default_crate_root.is_none()); default_crate_root = Some(file_id); default_cfg = meta.cfg; diff --git a/crates/hir_def/src/nameres/tests/mod_resolution.rs b/crates/hir_def/src/nameres/tests/mod_resolution.rs index 0b2b4429d..ec9d589a3 100644 --- a/crates/hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/hir_def/src/nameres/tests/mod_resolution.rs @@ -323,7 +323,7 @@ pub struct Baz; fn module_resolution_relative_path_outside_root() { check( r#" -//- /a/b/c/d/e/main.rs root: +//- /a/b/c/d/e/main.rs crate:main #[path="../../../../../outside.rs"] mod foo; diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 806ab06c1..e40b61a94 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -8,7 +8,6 @@ use stdx::{lines_with_ends, split_once, trim_indent}; pub struct Fixture { pub path: String, pub text: String, - pub explicit_root: bool, pub krate: Option, pub deps: Vec, pub cfg_atoms: Vec, @@ -65,7 +64,6 @@ impl Fixture { let path = components[0].to_string(); assert!(path.starts_with('/')); - let mut explicit_root = false; let mut krate = None; let mut deps = Vec::new(); let mut edition = None; @@ -75,7 +73,6 @@ impl Fixture { for component in components[1..].iter() { let (key, value) = split_once(component, ':').unwrap(); match key { - "root" => explicit_root = true, "crate" => krate = Some(value.to_string()), "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), "edition" => edition = Some(value.to_string()), @@ -101,7 +98,6 @@ impl Fixture { Fixture { path, text: String::new(), - explicit_root: explicit_root, krate: krate, deps, cfg_atoms, -- cgit v1.2.3