Make find_path tests adhere to style guide

This commit is contained in:
Jonas Schievink 2021-04-15 18:32:19 +02:00
parent 4dafc57019
commit 6acd0ac51a

View File

@ -425,106 +425,145 @@ mod tests {
#[test] #[test]
fn same_module() { fn same_module() {
let code = r#" check_found_path(
//- /main.rs r#"
struct S; //- /main.rs
$0 struct S;
"#; $0
check_found_path(code, "S", "S", "crate::S", "self::S"); "#,
"S",
"S",
"crate::S",
"self::S",
);
} }
#[test] #[test]
fn enum_variant() { fn enum_variant() {
let code = r#" check_found_path(
//- /main.rs r#"
enum E { A } //- /main.rs
$0 enum E { A }
"#; $0
check_found_path(code, "E::A", "E::A", "E::A", "E::A"); "#,
"E::A",
"E::A",
"E::A",
"E::A",
);
} }
#[test] #[test]
fn sub_module() { fn sub_module() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo { //- /main.rs
pub struct S; mod foo {
} pub struct S;
$0 }
"#; $0
check_found_path(code, "foo::S", "foo::S", "crate::foo::S", "self::foo::S"); "#,
"foo::S",
"foo::S",
"crate::foo::S",
"self::foo::S",
);
} }
#[test] #[test]
fn super_module() { fn super_module() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo; //- /main.rs
//- /foo.rs mod foo;
mod bar; //- /foo.rs
struct S; mod bar;
//- /foo/bar.rs struct S;
$0 //- /foo/bar.rs
"#; $0
check_found_path(code, "super::S", "super::S", "crate::foo::S", "super::S"); "#,
"super::S",
"super::S",
"crate::foo::S",
"super::S",
);
} }
#[test] #[test]
fn self_module() { fn self_module() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo; //- /main.rs
//- /foo.rs mod foo;
$0 //- /foo.rs
"#; $0
check_found_path(code, "self", "self", "crate::foo", "self"); "#,
"self",
"self",
"crate::foo",
"self",
);
} }
#[test] #[test]
fn crate_root() { fn crate_root() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo; //- /main.rs
//- /foo.rs mod foo;
$0 //- /foo.rs
"#; $0
check_found_path(code, "crate", "crate", "crate", "crate"); "#,
"crate",
"crate",
"crate",
"crate",
);
} }
#[test] #[test]
fn same_crate() { fn same_crate() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo; //- /main.rs
struct S; mod foo;
//- /foo.rs struct S;
$0 //- /foo.rs
"#; $0
check_found_path(code, "crate::S", "crate::S", "crate::S", "crate::S"); "#,
"crate::S",
"crate::S",
"crate::S",
"crate::S",
);
} }
#[test] #[test]
fn different_crate() { fn different_crate() {
let code = r#" check_found_path(
//- /main.rs crate:main deps:std r#"
$0 //- /main.rs crate:main deps:std
//- /std.rs crate:std $0
pub struct S; //- /std.rs crate:std
"#; pub struct S;
check_found_path(code, "std::S", "std::S", "std::S", "std::S"); "#,
"std::S",
"std::S",
"std::S",
"std::S",
);
} }
#[test] #[test]
fn different_crate_renamed() { fn different_crate_renamed() {
let code = r#"
//- /main.rs crate:main deps:std
extern crate std as std_renamed;
$0
//- /std.rs crate:std
pub struct S;
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:std
extern crate std as std_renamed;
$0
//- /std.rs crate:std
pub struct S;
"#,
"std_renamed::S", "std_renamed::S",
"std_renamed::S", "std_renamed::S",
"std_renamed::S", "std_renamed::S",
@ -537,41 +576,38 @@ mod tests {
cov_mark::check!(partially_imported); cov_mark::check!(partially_imported);
// Tests that short paths are used even for external items, when parts of the path are // Tests that short paths are used even for external items, when parts of the path are
// already in scope. // already in scope.
let code = r#"
//- /main.rs crate:main deps:syntax
use syntax::ast;
$0
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
}
}
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:syntax
use syntax::ast;
$0
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
}
}
"#,
"ast::ModuleItem", "ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
); );
let code = r#"
//- /main.rs crate:main deps:syntax
$0
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
}
}
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:syntax
$0
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
}
}
"#,
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
@ -581,68 +617,88 @@ mod tests {
#[test] #[test]
fn same_crate_reexport() { fn same_crate_reexport() {
let code = r#" check_found_path(
//- /main.rs r#"
mod bar { //- /main.rs
mod foo { pub(super) struct S; } mod bar {
pub(crate) use foo::*; mod foo { pub(super) struct S; }
} pub(crate) use foo::*;
$0 }
"#; $0
check_found_path(code, "bar::S", "bar::S", "crate::bar::S", "self::bar::S"); "#,
"bar::S",
"bar::S",
"crate::bar::S",
"self::bar::S",
);
} }
#[test] #[test]
fn same_crate_reexport_rename() { fn same_crate_reexport_rename() {
let code = r#" check_found_path(
//- /main.rs r#"
mod bar { //- /main.rs
mod foo { pub(super) struct S; } mod bar {
pub(crate) use foo::S as U; mod foo { pub(super) struct S; }
} pub(crate) use foo::S as U;
$0 }
"#; $0
check_found_path(code, "bar::U", "bar::U", "crate::bar::U", "self::bar::U"); "#,
"bar::U",
"bar::U",
"crate::bar::U",
"self::bar::U",
);
} }
#[test] #[test]
fn different_crate_reexport() { fn different_crate_reexport() {
let code = r#" check_found_path(
//- /main.rs crate:main deps:std r#"
$0 //- /main.rs crate:main deps:std
//- /std.rs crate:std deps:core $0
pub use core::S; //- /std.rs crate:std deps:core
//- /core.rs crate:core pub use core::S;
pub struct S; //- /core.rs crate:core
"#; pub struct S;
check_found_path(code, "std::S", "std::S", "std::S", "std::S"); "#,
"std::S",
"std::S",
"std::S",
"std::S",
);
} }
#[test] #[test]
fn prelude() { fn prelude() {
let code = r#" check_found_path(
//- /main.rs crate:main deps:std r#"
$0 //- /main.rs crate:main deps:std
//- /std.rs crate:std $0
pub mod prelude { pub struct S; } //- /std.rs crate:std
#[prelude_import] pub mod prelude { pub struct S; }
pub use prelude::*; #[prelude_import]
"#; pub use prelude::*;
check_found_path(code, "S", "S", "S", "S"); "#,
"S",
"S",
"S",
"S",
);
} }
#[test] #[test]
fn enum_variant_from_prelude() { fn enum_variant_from_prelude() {
let code = r#" let code = r#"
//- /main.rs crate:main deps:std //- /main.rs crate:main deps:std
$0 $0
//- /std.rs crate:std //- /std.rs crate:std
pub mod prelude { pub mod prelude {
pub enum Option<T> { Some(T), None } pub enum Option<T> { Some(T), None }
pub use Option::*; pub use Option::*;
} }
#[prelude_import] #[prelude_import]
pub use prelude::*; pub use prelude::*;
"#; "#;
check_found_path(code, "None", "None", "None", "None"); check_found_path(code, "None", "None", "None", "None");
check_found_path(code, "Some", "Some", "Some", "Some"); check_found_path(code, "Some", "Some", "Some", "Some");
@ -650,71 +706,85 @@ mod tests {
#[test] #[test]
fn shortest_path() { fn shortest_path() {
let code = r#" check_found_path(
//- /main.rs r#"
pub mod foo; //- /main.rs
pub mod baz; pub mod foo;
struct S; pub mod baz;
$0 struct S;
//- /foo.rs $0
pub mod bar { pub struct S; } //- /foo.rs
//- /baz.rs pub mod bar { pub struct S; }
pub use crate::foo::bar::S; //- /baz.rs
"#; pub use crate::foo::bar::S;
check_found_path(code, "baz::S", "baz::S", "crate::baz::S", "self::baz::S"); "#,
"baz::S",
"baz::S",
"crate::baz::S",
"self::baz::S",
);
} }
#[test] #[test]
fn discount_private_imports() { fn discount_private_imports() {
let code = r#" check_found_path(
//- /main.rs r#"
mod foo; //- /main.rs
pub mod bar { pub struct S; } mod foo;
use bar::S; pub mod bar { pub struct S; }
//- /foo.rs use bar::S;
$0 //- /foo.rs
"#; $0
// crate::S would be shorter, but using private imports seems wrong "#,
check_found_path(code, "crate::bar::S", "crate::bar::S", "crate::bar::S", "crate::bar::S"); // crate::S would be shorter, but using private imports seems wrong
"crate::bar::S",
"crate::bar::S",
"crate::bar::S",
"crate::bar::S",
);
} }
#[test] #[test]
fn import_cycle() { fn import_cycle() {
let code = r#" check_found_path(
//- /main.rs r#"
pub mod foo; //- /main.rs
pub mod bar; pub mod foo;
pub mod baz; pub mod bar;
//- /bar.rs pub mod baz;
$0 //- /bar.rs
//- /foo.rs $0
pub use super::baz; //- /foo.rs
pub struct S; pub use super::baz;
//- /baz.rs pub struct S;
pub use super::foo; //- /baz.rs
"#; pub use super::foo;
check_found_path(code, "crate::foo::S", "crate::foo::S", "crate::foo::S", "crate::foo::S"); "#,
"crate::foo::S",
"crate::foo::S",
"crate::foo::S",
"crate::foo::S",
);
} }
#[test] #[test]
fn prefer_std_paths_over_alloc() { fn prefer_std_paths_over_alloc() {
cov_mark::check!(prefer_std_paths); cov_mark::check!(prefer_std_paths);
let code = r#"
//- /main.rs crate:main deps:alloc,std
$0
//- /std.rs crate:std deps:alloc
pub mod sync {
pub use alloc::sync::Arc;
}
//- /zzz.rs crate:alloc
pub mod sync {
pub struct Arc;
}
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:alloc,std
$0
//- /std.rs crate:std deps:alloc
pub mod sync {
pub use alloc::sync::Arc;
}
//- /zzz.rs crate:alloc
pub mod sync {
pub struct Arc;
}
"#,
"std::sync::Arc", "std::sync::Arc",
"std::sync::Arc", "std::sync::Arc",
"std::sync::Arc", "std::sync::Arc",
@ -725,26 +795,25 @@ mod tests {
#[test] #[test]
fn prefer_core_paths_over_std() { fn prefer_core_paths_over_std() {
cov_mark::check!(prefer_no_std_paths); cov_mark::check!(prefer_no_std_paths);
let code = r#"
//- /main.rs crate:main deps:core,std
#![no_std]
$0
//- /std.rs crate:std deps:core
pub mod fmt {
pub use core::fmt::Error;
}
//- /zzz.rs crate:core
pub mod fmt {
pub struct Error;
}
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:core,std
#![no_std]
$0
//- /std.rs crate:std deps:core
pub mod fmt {
pub use core::fmt::Error;
}
//- /zzz.rs crate:core
pub mod fmt {
pub struct Error;
}
"#,
"core::fmt::Error", "core::fmt::Error",
"core::fmt::Error", "core::fmt::Error",
"core::fmt::Error", "core::fmt::Error",
@ -754,26 +823,25 @@ mod tests {
#[test] #[test]
fn prefer_alloc_paths_over_std() { fn prefer_alloc_paths_over_std() {
let code = r#"
//- /main.rs crate:main deps:alloc,std
#![no_std]
$0
//- /std.rs crate:std deps:alloc
pub mod sync {
pub use alloc::sync::Arc;
}
//- /zzz.rs crate:alloc
pub mod sync {
pub struct Arc;
}
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:alloc,std
#![no_std]
$0
//- /std.rs crate:std deps:alloc
pub mod sync {
pub use alloc::sync::Arc;
}
//- /zzz.rs crate:alloc
pub mod sync {
pub struct Arc;
}
"#,
"alloc::sync::Arc", "alloc::sync::Arc",
"alloc::sync::Arc", "alloc::sync::Arc",
"alloc::sync::Arc", "alloc::sync::Arc",
@ -783,20 +851,19 @@ mod tests {
#[test] #[test]
fn prefer_shorter_paths_if_not_alloc() { fn prefer_shorter_paths_if_not_alloc() {
let code = r#"
//- /main.rs crate:main deps:megaalloc,std
$0
//- /std.rs crate:std deps:megaalloc
pub mod sync {
pub use megaalloc::sync::Arc;
}
//- /zzz.rs crate:megaalloc
pub struct Arc;
"#;
check_found_path( check_found_path(
code, r#"
//- /main.rs crate:main deps:megaalloc,std
$0
//- /std.rs crate:std deps:megaalloc
pub mod sync {
pub use megaalloc::sync::Arc;
}
//- /zzz.rs crate:megaalloc
pub struct Arc;
"#,
"megaalloc::Arc", "megaalloc::Arc",
"megaalloc::Arc", "megaalloc::Arc",
"megaalloc::Arc", "megaalloc::Arc",
@ -807,12 +874,12 @@ mod tests {
#[test] #[test]
fn builtins_are_in_scope() { fn builtins_are_in_scope() {
let code = r#" let code = r#"
//- /main.rs //- /main.rs
$0 $0
pub mod primitive { pub mod primitive {
pub use u8; pub use u8;
} }
"#; "#;
check_found_path(code, "u8", "u8", "u8", "u8"); check_found_path(code, "u8", "u8", "u8", "u8");
check_found_path(code, "u16", "u16", "u16", "u16"); check_found_path(code, "u16", "u16", "u16", "u16");
@ -822,10 +889,10 @@ mod tests {
fn inner_items() { fn inner_items() {
check_found_path( check_found_path(
r#" r#"
fn main() { fn main() {
struct Inner {} struct Inner {}
$0 $0
} }
"#, "#,
"Inner", "Inner",
"Inner", "Inner",
@ -838,12 +905,12 @@ mod tests {
fn inner_items_from_outer_scope() { fn inner_items_from_outer_scope() {
check_found_path( check_found_path(
r#" r#"
fn main() { fn main() {
struct Struct {} struct Struct {}
{ {
$0 $0
} }
} }
"#, "#,
"Struct", "Struct",
"Struct", "Struct",
@ -857,14 +924,14 @@ mod tests {
cov_mark::check!(prefixed_in_block_expression); cov_mark::check!(prefixed_in_block_expression);
check_found_path( check_found_path(
r#" r#"
fn main() { fn main() {
mod module { mod module {
struct Struct {} struct Struct {}
} }
{ {
$0 $0
} }
} }
"#, "#,
"module::Struct", "module::Struct",
"module::Struct", "module::Struct",
@ -877,14 +944,14 @@ mod tests {
fn outer_items_with_inner_items_present() { fn outer_items_with_inner_items_present() {
check_found_path( check_found_path(
r#" r#"
mod module { mod module {
pub struct CompleteMe; pub struct CompleteMe;
} }
fn main() { fn main() {
fn inner() {} fn inner() {}
$0 $0
} }
"#, "#,
"module::CompleteMe", "module::CompleteMe",
"module::CompleteMe", "module::CompleteMe",