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() entry.text.clone()
}; };
let explicit_root = entry.explicit_root;
let meta = FileMeta::from(entry); let meta = FileMeta::from(entry);
assert!(meta.path.starts_with(&source_root_prefix)); 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); let dep = CrateName::normalize_dashes(&dep);
crate_deps.push((crate_name.clone(), 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()); assert!(default_crate_root.is_none());
default_crate_root = Some(file_id); default_crate_root = Some(file_id);
default_cfg = meta.cfg; default_cfg = meta.cfg;

View File

@ -323,13 +323,26 @@ fn module_resolution_relative_path_2() {
fn module_resolution_relative_path_outside_root() { fn module_resolution_relative_path_outside_root() {
check( check(
r#" r#"
//- /main.rs //- /a/b/c/d/e/main.rs root:
#[path="../../../../../outside.rs"] #[path="../../../../../outside.rs"]
mod foo; mod foo;
//- /outside.rs
mod bar;
//- /bar.rs
pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
"#]], foo: t
crate::foo
bar: t
crate::foo::bar
Baz: t v
"#]],
); );
} }

View File

@ -8,6 +8,7 @@
pub struct Fixture { pub struct Fixture {
pub path: String, pub path: String,
pub text: String, pub text: String,
pub explicit_root: bool,
pub krate: Option<String>, pub krate: Option<String>,
pub deps: Vec<String>, pub deps: Vec<String>,
pub cfg_atoms: Vec<String>, pub cfg_atoms: Vec<String>,
@ -64,6 +65,7 @@ fn parse_meta_line(meta: &str) -> Fixture {
let path = components[0].to_string(); let path = components[0].to_string();
assert!(path.starts_with('/')); assert!(path.starts_with('/'));
let mut explicit_root = false;
let mut krate = None; let mut krate = None;
let mut deps = Vec::new(); let mut deps = Vec::new();
let mut edition = None; let mut edition = None;
@ -73,6 +75,7 @@ fn parse_meta_line(meta: &str) -> Fixture {
for component in components[1..].iter() { for component in components[1..].iter() {
let (key, value) = split_once(component, ':').unwrap(); let (key, value) = split_once(component, ':').unwrap();
match key { match key {
"root" => explicit_root = true,
"crate" => krate = Some(value.to_string()), "crate" => krate = Some(value.to_string()),
"deps" => deps = value.split(',').map(|it| it.to_string()).collect(), "deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
"edition" => edition = Some(value.to_string()), "edition" => edition = Some(value.to_string()),
@ -98,6 +101,7 @@ fn parse_meta_line(meta: &str) -> Fixture {
Fixture { Fixture {
path, path,
text: String::new(), text: String::new(),
explicit_root: explicit_root,
krate: krate, krate: krate,
deps, deps,
cfg_atoms, cfg_atoms,