mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
Make find_path tests adhere to style guide
This commit is contained in:
parent
4dafc57019
commit
6acd0ac51a
@ -425,39 +425,55 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn same_module() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
struct S;
|
||||
$0
|
||||
"#;
|
||||
check_found_path(code, "S", "S", "crate::S", "self::S");
|
||||
"#,
|
||||
"S",
|
||||
"S",
|
||||
"crate::S",
|
||||
"self::S",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_variant() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
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]
|
||||
fn sub_module() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo {
|
||||
pub struct S;
|
||||
}
|
||||
$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]
|
||||
fn super_module() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo;
|
||||
//- /foo.rs
|
||||
@ -465,66 +481,89 @@ mod tests {
|
||||
struct S;
|
||||
//- /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]
|
||||
fn self_module() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo;
|
||||
//- /foo.rs
|
||||
$0
|
||||
"#;
|
||||
check_found_path(code, "self", "self", "crate::foo", "self");
|
||||
"#,
|
||||
"self",
|
||||
"self",
|
||||
"crate::foo",
|
||||
"self",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crate_root() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo;
|
||||
//- /foo.rs
|
||||
$0
|
||||
"#;
|
||||
check_found_path(code, "crate", "crate", "crate", "crate");
|
||||
"#,
|
||||
"crate",
|
||||
"crate",
|
||||
"crate",
|
||||
"crate",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_crate() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo;
|
||||
struct S;
|
||||
//- /foo.rs
|
||||
$0
|
||||
"#;
|
||||
check_found_path(code, "crate::S", "crate::S", "crate::S", "crate::S");
|
||||
"#,
|
||||
"crate::S",
|
||||
"crate::S",
|
||||
"crate::S",
|
||||
"crate::S",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_crate() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
$0
|
||||
//- /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]
|
||||
fn different_crate_renamed() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
extern crate std as std_renamed;
|
||||
$0
|
||||
//- /std.rs crate:std
|
||||
pub struct S;
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"std_renamed::S",
|
||||
"std_renamed::S",
|
||||
"std_renamed::S",
|
||||
@ -537,7 +576,8 @@ mod tests {
|
||||
cov_mark::check!(partially_imported);
|
||||
// Tests that short paths are used even for external items, when parts of the path are
|
||||
// already in scope.
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:syntax
|
||||
|
||||
use syntax::ast;
|
||||
@ -549,18 +589,16 @@ mod tests {
|
||||
A, B, C,
|
||||
}
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"ast::ModuleItem",
|
||||
"syntax::ast::ModuleItem",
|
||||
"syntax::ast::ModuleItem",
|
||||
"syntax::ast::ModuleItem",
|
||||
);
|
||||
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:syntax
|
||||
|
||||
$0
|
||||
|
||||
//- /lib.rs crate:syntax
|
||||
@ -569,9 +607,7 @@ mod tests {
|
||||
A, B, C,
|
||||
}
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"syntax::ast::ModuleItem",
|
||||
"syntax::ast::ModuleItem",
|
||||
"syntax::ast::ModuleItem",
|
||||
@ -581,54 +617,74 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn same_crate_reexport() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod bar {
|
||||
mod foo { pub(super) struct S; }
|
||||
pub(crate) use foo::*;
|
||||
}
|
||||
$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]
|
||||
fn same_crate_reexport_rename() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod bar {
|
||||
mod foo { pub(super) struct S; }
|
||||
pub(crate) use foo::S as U;
|
||||
}
|
||||
$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]
|
||||
fn different_crate_reexport() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
$0
|
||||
//- /std.rs crate:std deps:core
|
||||
pub use core::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]
|
||||
fn prelude() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
$0
|
||||
//- /std.rs crate:std
|
||||
pub mod prelude { pub struct S; }
|
||||
#[prelude_import]
|
||||
pub use prelude::*;
|
||||
"#;
|
||||
check_found_path(code, "S", "S", "S", "S");
|
||||
"#,
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -650,7 +706,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn shortest_path() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
pub mod foo;
|
||||
pub mod baz;
|
||||
@ -660,27 +717,37 @@ mod tests {
|
||||
pub mod bar { pub struct 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]
|
||||
fn discount_private_imports() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
mod foo;
|
||||
pub mod bar { pub struct S; }
|
||||
use bar::S;
|
||||
//- /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::bar::S",
|
||||
"crate::bar::S",
|
||||
"crate::bar::S",
|
||||
"crate::bar::S",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_cycle() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs
|
||||
pub mod foo;
|
||||
pub mod bar;
|
||||
@ -692,14 +759,19 @@ mod tests {
|
||||
pub struct S;
|
||||
//- /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]
|
||||
fn prefer_std_paths_over_alloc() {
|
||||
cov_mark::check!(prefer_std_paths);
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:alloc,std
|
||||
$0
|
||||
|
||||
@ -712,9 +784,7 @@ mod tests {
|
||||
pub mod sync {
|
||||
pub struct Arc;
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"std::sync::Arc",
|
||||
"std::sync::Arc",
|
||||
"std::sync::Arc",
|
||||
@ -725,7 +795,8 @@ mod tests {
|
||||
#[test]
|
||||
fn prefer_core_paths_over_std() {
|
||||
cov_mark::check!(prefer_no_std_paths);
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:core,std
|
||||
#![no_std]
|
||||
|
||||
@ -742,9 +813,7 @@ mod tests {
|
||||
pub mod fmt {
|
||||
pub struct Error;
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"core::fmt::Error",
|
||||
"core::fmt::Error",
|
||||
"core::fmt::Error",
|
||||
@ -754,7 +823,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prefer_alloc_paths_over_std() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:alloc,std
|
||||
#![no_std]
|
||||
|
||||
@ -771,9 +841,7 @@ mod tests {
|
||||
pub mod sync {
|
||||
pub struct Arc;
|
||||
}
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"alloc::sync::Arc",
|
||||
"alloc::sync::Arc",
|
||||
"alloc::sync::Arc",
|
||||
@ -783,7 +851,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prefer_shorter_paths_if_not_alloc() {
|
||||
let code = r#"
|
||||
check_found_path(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:megaalloc,std
|
||||
$0
|
||||
|
||||
@ -794,9 +863,7 @@ mod tests {
|
||||
|
||||
//- /zzz.rs crate:megaalloc
|
||||
pub struct Arc;
|
||||
"#;
|
||||
check_found_path(
|
||||
code,
|
||||
"#,
|
||||
"megaalloc::Arc",
|
||||
"megaalloc::Arc",
|
||||
"megaalloc::Arc",
|
||||
|
Loading…
Reference in New Issue
Block a user