Test Fixture ExplicitRoot + ModuleResolutionRelativePathOutsideRoot.

This commit is contained in:
James Leitch 2020-11-01 17:20:55 -07:00
parent bf84e4958e
commit d2d7a4403c
3 changed files with 22 additions and 3 deletions

View File

@ -150,6 +150,8 @@ pub fn parse(ra_fixture: &str) -> 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 @@ pub fn parse(ra_fixture: &str) -> 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;

View File

@ -323,13 +323,26 @@ fn module_resolution_relative_path_2() {
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
"#]],
);
}

View File

@ -8,6 +8,7 @@
pub struct Fixture {
pub path: String,
pub text: String,
pub explicit_root: bool,
pub krate: Option<String>,
pub deps: Vec<String>,
pub cfg_atoms: Vec<String>,
@ -64,6 +65,7 @@ fn parse_meta_line(meta: &str) -> 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 @@ fn parse_meta_line(meta: &str) -> 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 @@ fn parse_meta_line(meta: &str) -> Fixture {
Fixture {
path,
text: String::new(),
explicit_root: explicit_root,
krate: krate,
deps,
cfg_atoms,