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,39 +425,55 @@ mod tests {
#[test] #[test]
fn same_module() { fn same_module() {
let code = r#" check_found_path(
r#"
//- /main.rs //- /main.rs
struct S; struct S;
$0 $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(
r#"
//- /main.rs //- /main.rs
enum E { A } enum E { A }
$0 $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(
r#"
//- /main.rs //- /main.rs
mod foo { mod foo {
pub struct S; 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(
r#"
//- /main.rs //- /main.rs
mod foo; mod foo;
//- /foo.rs //- /foo.rs
@ -465,66 +481,89 @@ mod tests {
struct S; struct S;
//- /foo/bar.rs //- /foo/bar.rs
$0 $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(
r#"
//- /main.rs //- /main.rs
mod foo; mod foo;
//- /foo.rs //- /foo.rs
$0 $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(
r#"
//- /main.rs //- /main.rs
mod foo; mod foo;
//- /foo.rs //- /foo.rs
$0 $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(
r#"
//- /main.rs //- /main.rs
mod foo; mod foo;
struct S; struct S;
//- /foo.rs //- /foo.rs
$0 $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(
r#"
//- /main.rs crate:main deps:std //- /main.rs crate:main deps:std
$0 $0
//- /std.rs crate:std //- /std.rs crate:std
pub struct S; 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#" check_found_path(
r#"
//- /main.rs crate:main deps:std //- /main.rs crate:main deps:std
extern crate std as std_renamed; extern crate std as std_renamed;
$0 $0
//- /std.rs crate:std //- /std.rs crate:std
pub struct S; pub struct S;
"#; "#,
check_found_path(
code,
"std_renamed::S", "std_renamed::S",
"std_renamed::S", "std_renamed::S",
"std_renamed::S", "std_renamed::S",
@ -537,7 +576,8 @@ 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#" check_found_path(
r#"
//- /main.rs crate:main deps:syntax //- /main.rs crate:main deps:syntax
use syntax::ast; use syntax::ast;
@ -549,18 +589,16 @@ mod tests {
A, B, C, A, B, C,
} }
} }
"#; "#,
check_found_path(
code,
"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#" check_found_path(
r#"
//- /main.rs crate:main deps:syntax //- /main.rs crate:main deps:syntax
$0 $0
//- /lib.rs crate:syntax //- /lib.rs crate:syntax
@ -569,9 +607,7 @@ mod tests {
A, B, C, A, B, C,
} }
} }
"#; "#,
check_found_path(
code,
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
"syntax::ast::ModuleItem", "syntax::ast::ModuleItem",
@ -581,54 +617,74 @@ mod tests {
#[test] #[test]
fn same_crate_reexport() { fn same_crate_reexport() {
let code = r#" check_found_path(
r#"
//- /main.rs //- /main.rs
mod bar { mod bar {
mod foo { pub(super) struct S; } mod foo { pub(super) struct S; }
pub(crate) use foo::*; 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(
r#"
//- /main.rs //- /main.rs
mod bar { mod bar {
mod foo { pub(super) struct S; } mod foo { pub(super) struct S; }
pub(crate) use foo::S as U; 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(
r#"
//- /main.rs crate:main deps:std //- /main.rs crate:main deps:std
$0 $0
//- /std.rs crate:std deps:core //- /std.rs crate:std deps:core
pub use core::S; pub use core::S;
//- /core.rs crate:core //- /core.rs crate:core
pub struct S; 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(
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 struct S; } pub mod prelude { pub struct S; }
#[prelude_import] #[prelude_import]
pub use prelude::*; pub use prelude::*;
"#; "#,
check_found_path(code, "S", "S", "S", "S"); "S",
"S",
"S",
"S",
);
} }
#[test] #[test]
@ -650,7 +706,8 @@ mod tests {
#[test] #[test]
fn shortest_path() { fn shortest_path() {
let code = r#" check_found_path(
r#"
//- /main.rs //- /main.rs
pub mod foo; pub mod foo;
pub mod baz; pub mod baz;
@ -660,27 +717,37 @@ mod tests {
pub mod bar { pub struct S; } pub mod bar { pub struct S; }
//- /baz.rs //- /baz.rs
pub use crate::foo::bar::S; 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(
r#"
//- /main.rs //- /main.rs
mod foo; mod foo;
pub mod bar { pub struct S; } pub mod bar { pub struct S; }
use bar::S; use bar::S;
//- /foo.rs //- /foo.rs
$0 $0
"#; "#,
// crate::S would be shorter, but using private imports seems wrong // 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::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(
r#"
//- /main.rs //- /main.rs
pub mod foo; pub mod foo;
pub mod bar; pub mod bar;
@ -692,14 +759,19 @@ mod tests {
pub struct S; pub struct S;
//- /baz.rs //- /baz.rs
pub use super::foo; 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#" check_found_path(
r#"
//- /main.rs crate:main deps:alloc,std //- /main.rs crate:main deps:alloc,std
$0 $0
@ -712,9 +784,7 @@ mod tests {
pub mod sync { pub mod sync {
pub struct Arc; pub struct Arc;
} }
"#; "#,
check_found_path(
code,
"std::sync::Arc", "std::sync::Arc",
"std::sync::Arc", "std::sync::Arc",
"std::sync::Arc", "std::sync::Arc",
@ -725,7 +795,8 @@ 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#" check_found_path(
r#"
//- /main.rs crate:main deps:core,std //- /main.rs crate:main deps:core,std
#![no_std] #![no_std]
@ -742,9 +813,7 @@ mod tests {
pub mod fmt { pub mod fmt {
pub struct Error; pub struct Error;
} }
"#; "#,
check_found_path(
code,
"core::fmt::Error", "core::fmt::Error",
"core::fmt::Error", "core::fmt::Error",
"core::fmt::Error", "core::fmt::Error",
@ -754,7 +823,8 @@ mod tests {
#[test] #[test]
fn prefer_alloc_paths_over_std() { fn prefer_alloc_paths_over_std() {
let code = r#" check_found_path(
r#"
//- /main.rs crate:main deps:alloc,std //- /main.rs crate:main deps:alloc,std
#![no_std] #![no_std]
@ -771,9 +841,7 @@ mod tests {
pub mod sync { pub mod sync {
pub struct Arc; pub struct Arc;
} }
"#; "#,
check_found_path(
code,
"alloc::sync::Arc", "alloc::sync::Arc",
"alloc::sync::Arc", "alloc::sync::Arc",
"alloc::sync::Arc", "alloc::sync::Arc",
@ -783,7 +851,8 @@ mod tests {
#[test] #[test]
fn prefer_shorter_paths_if_not_alloc() { fn prefer_shorter_paths_if_not_alloc() {
let code = r#" check_found_path(
r#"
//- /main.rs crate:main deps:megaalloc,std //- /main.rs crate:main deps:megaalloc,std
$0 $0
@ -794,9 +863,7 @@ mod tests {
//- /zzz.rs crate:megaalloc //- /zzz.rs crate:megaalloc
pub struct Arc; pub struct Arc;
"#; "#,
check_found_path(
code,
"megaalloc::Arc", "megaalloc::Arc",
"megaalloc::Arc", "megaalloc::Arc",
"megaalloc::Arc", "megaalloc::Arc",