mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Colorize more test fixtures
This commit is contained in:
parent
87d24e7caa
commit
dbb940fa7d
@ -137,8 +137,8 @@ mod tests {
|
||||
documentation: &'a str,
|
||||
}
|
||||
|
||||
fn check_detail_and_documentation(fixture: &str, expected: DetailAndDocumentation) {
|
||||
let (analysis, position) = analysis_and_position(fixture);
|
||||
fn check_detail_and_documentation(ra_fixture: &str, expected: DetailAndDocumentation) {
|
||||
let (analysis, position) = analysis_and_position(ra_fixture);
|
||||
let config = CompletionConfig::default();
|
||||
let completions = analysis.completions(&config, position).unwrap().unwrap();
|
||||
for item in completions {
|
||||
|
@ -324,10 +324,10 @@ mod tests {
|
||||
/// * a diagnostic is produced
|
||||
/// * this diagnostic touches the input cursor position
|
||||
/// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
|
||||
fn check_apply_diagnostic_fix_from_position(fixture: &str, after: &str) {
|
||||
fn check_apply_diagnostic_fix_from_position(ra_fixture: &str, after: &str) {
|
||||
let after = trim_indent(after);
|
||||
|
||||
let (analysis, file_position) = analysis_and_position(fixture);
|
||||
let (analysis, file_position) = analysis_and_position(ra_fixture);
|
||||
let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap();
|
||||
let mut fix = diagnostic.fix.unwrap();
|
||||
let edit = fix.source_change.source_file_edits.pop().unwrap().edit;
|
||||
@ -365,14 +365,14 @@ mod tests {
|
||||
|
||||
/// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
|
||||
/// apply to the file containing the cursor.
|
||||
fn check_no_diagnostic_for_target_file(fixture: &str) {
|
||||
let (analysis, file_position) = analysis_and_position(fixture);
|
||||
fn check_no_diagnostic_for_target_file(ra_fixture: &str) {
|
||||
let (analysis, file_position) = analysis_and_position(ra_fixture);
|
||||
let diagnostics = analysis.diagnostics(file_position.file_id).unwrap();
|
||||
assert_eq!(diagnostics.len(), 0);
|
||||
}
|
||||
|
||||
fn check_no_diagnostic(content: &str) {
|
||||
let (analysis, file_id) = single_file(content);
|
||||
fn check_no_diagnostic(ra_fixture: &str) {
|
||||
let (analysis, file_id) = single_file(ra_fixture);
|
||||
let diagnostics = analysis.diagnostics(file_id).unwrap();
|
||||
assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one");
|
||||
}
|
||||
@ -473,7 +473,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
|
||||
let content = r#"
|
||||
check_no_diagnostic_for_target_file(
|
||||
r"
|
||||
//- /main.rs
|
||||
use core::result::Result::{self, Ok, Err};
|
||||
|
||||
@ -485,13 +486,14 @@ mod tests {
|
||||
pub mod result {
|
||||
pub enum Result<T, E> { Ok(T), Err(E) }
|
||||
}
|
||||
"#;
|
||||
check_no_diagnostic_for_target_file(content);
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() {
|
||||
let content = r#"
|
||||
check_no_diagnostic_for_target_file(
|
||||
r"
|
||||
//- /main.rs
|
||||
use core::result::Result::{self, Ok, Err};
|
||||
|
||||
@ -508,8 +510,8 @@ mod tests {
|
||||
pub mod result {
|
||||
pub enum Result<T, E> { Ok(T), Err(E) }
|
||||
}
|
||||
"#;
|
||||
check_no_diagnostic_for_target_file(content);
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -618,7 +620,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_fill_struct_fields_no_diagnostic() {
|
||||
let content = r"
|
||||
check_no_diagnostic(
|
||||
r"
|
||||
struct TestStruct {
|
||||
one: i32,
|
||||
two: i64,
|
||||
@ -628,14 +631,14 @@ mod tests {
|
||||
let one = 1;
|
||||
let s = TestStruct{ one, two: 2 };
|
||||
}
|
||||
";
|
||||
|
||||
check_no_diagnostic(content);
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fill_struct_fields_no_diagnostic_on_spread() {
|
||||
let content = r"
|
||||
check_no_diagnostic(
|
||||
r"
|
||||
struct TestStruct {
|
||||
one: i32,
|
||||
two: i64,
|
||||
@ -645,9 +648,8 @@ mod tests {
|
||||
let one = 1;
|
||||
let s = TestStruct{ ..a };
|
||||
}
|
||||
";
|
||||
|
||||
check_no_diagnostic(content);
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -55,8 +55,8 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
|
||||
mod tests {
|
||||
use crate::mock_analysis::analysis_and_position;
|
||||
|
||||
fn check_goto(fixture: &str, expected: &str) {
|
||||
let (analysis, pos) = analysis_and_position(fixture);
|
||||
fn check_goto(ra_fixture: &str, expected: &str) {
|
||||
let (analysis, pos) = analysis_and_position(ra_fixture);
|
||||
|
||||
let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info;
|
||||
assert_eq!(navs.len(), 1);
|
||||
@ -67,7 +67,7 @@ mod tests {
|
||||
#[test]
|
||||
fn goto_type_definition_works_simple() {
|
||||
check_goto(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct Foo;
|
||||
fn foo() {
|
||||
@ -82,7 +82,7 @@ mod tests {
|
||||
#[test]
|
||||
fn goto_type_definition_works_simple_ref() {
|
||||
check_goto(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct Foo;
|
||||
fn foo() {
|
||||
@ -97,7 +97,7 @@ mod tests {
|
||||
#[test]
|
||||
fn goto_type_definition_works_through_macro() {
|
||||
check_goto(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
macro_rules! id {
|
||||
($($tt:tt)*) => { $($tt)* }
|
||||
@ -116,7 +116,7 @@ mod tests {
|
||||
#[test]
|
||||
fn goto_type_definition_for_param() {
|
||||
check_goto(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct Foo;
|
||||
fn foo(<|>f: Foo) {}
|
||||
@ -128,7 +128,7 @@ mod tests {
|
||||
#[test]
|
||||
fn goto_type_definition_for_tuple_field() {
|
||||
check_goto(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct Foo;
|
||||
struct Bar(Foo);
|
||||
|
@ -417,8 +417,8 @@ mod tests {
|
||||
assert_eq!(offset, position.into());
|
||||
}
|
||||
|
||||
fn check_hover_result(fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) {
|
||||
let (analysis, position) = analysis_and_position(fixture);
|
||||
fn check_hover_result(ra_fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) {
|
||||
let (analysis, position) = analysis_and_position(ra_fixture);
|
||||
let hover = analysis.hover(position).unwrap().unwrap();
|
||||
let mut results = Vec::from(hover.info.results());
|
||||
results.sort();
|
||||
@ -435,8 +435,8 @@ mod tests {
|
||||
(content[hover.range].to_string(), hover.info.actions().to_vec())
|
||||
}
|
||||
|
||||
fn check_hover_no_result(fixture: &str) {
|
||||
let (analysis, position) = analysis_and_position(fixture);
|
||||
fn check_hover_no_result(ra_fixture: &str) {
|
||||
let (analysis, position) = analysis_and_position(ra_fixture);
|
||||
assert!(analysis.hover(position).unwrap().is_none());
|
||||
}
|
||||
|
||||
@ -923,7 +923,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_through_macro() {
|
||||
let (hover_on, _) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
macro_rules! id {
|
||||
($($tt:tt)*) => { $($tt)* }
|
||||
@ -944,7 +944,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_through_expr_in_macro() {
|
||||
let (hover_on, _) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
macro_rules! id {
|
||||
($($tt:tt)*) => { $($tt)* }
|
||||
@ -962,7 +962,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_through_expr_in_macro_recursive() {
|
||||
let (hover_on, _) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
macro_rules! id_deep {
|
||||
($($tt:tt)*) => { $($tt)* }
|
||||
@ -983,7 +983,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_through_func_in_macro_recursive() {
|
||||
let (hover_on, _) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
macro_rules! id_deep {
|
||||
($($tt:tt)*) => { $($tt)* }
|
||||
@ -1026,7 +1026,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_through_assert_macro() {
|
||||
let (hover_on, _) = check_hover_result(
|
||||
r#"
|
||||
r"
|
||||
//- /lib.rs
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! assert {}
|
||||
@ -1035,7 +1035,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
fn foo() {
|
||||
assert!(ba<|>r());
|
||||
}
|
||||
"#,
|
||||
",
|
||||
&["fn bar() -> bool"],
|
||||
);
|
||||
|
||||
@ -1077,14 +1077,14 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_function_show_qualifiers() {
|
||||
check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
async fn foo<|>() {}
|
||||
",
|
||||
&["async fn foo()"],
|
||||
);
|
||||
check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
pub const unsafe fn foo<|>() {}
|
||||
",
|
||||
@ -1102,7 +1102,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_trait_show_qualifiers() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
unsafe trait foo<|>() {}
|
||||
",
|
||||
@ -1114,7 +1114,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_mod_with_same_name_as_function() {
|
||||
check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
use self::m<|>y::Bar;
|
||||
|
||||
@ -1237,7 +1237,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_trait_has_impl_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait foo<|>() {}
|
||||
",
|
||||
@ -1249,7 +1249,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_struct_has_impl_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct foo<|>() {}
|
||||
",
|
||||
@ -1261,7 +1261,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_union_has_impl_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
union foo<|>() {}
|
||||
",
|
||||
@ -1273,7 +1273,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_enum_has_impl_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
enum foo<|>() {
|
||||
A,
|
||||
@ -1288,7 +1288,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_test_has_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
#[test]
|
||||
fn foo_<|>test() {}
|
||||
@ -1332,7 +1332,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_test_mod_has_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
mod tests<|> {
|
||||
#[test]
|
||||
@ -1373,7 +1373,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_struct_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
struct S{ f1: u32 }
|
||||
|
||||
@ -1416,7 +1416,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_generic_struct_has_goto_type_actions() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
struct Arg(u32);
|
||||
struct S<T>{ f1: T }
|
||||
@ -1479,7 +1479,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_generic_struct_has_flattened_goto_type_actions() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
struct Arg(u32);
|
||||
struct S<T>{ f1: T }
|
||||
@ -1542,7 +1542,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_tuple_has_goto_type_actions() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
struct A(u32);
|
||||
struct B(u32);
|
||||
@ -1627,7 +1627,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_return_impl_trait_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo {}
|
||||
|
||||
@ -1672,7 +1672,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_generic_return_impl_trait_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo<T> {}
|
||||
struct S;
|
||||
@ -1737,7 +1737,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_return_impl_traits_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo {}
|
||||
trait Bar {}
|
||||
@ -1802,7 +1802,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_generic_return_impl_traits_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo<T> {}
|
||||
trait Bar<T> {}
|
||||
@ -1907,7 +1907,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_arg_impl_trait_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait Foo {}
|
||||
fn foo(ar<|>g: &impl Foo) {}
|
||||
@ -1947,7 +1947,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_arg_impl_traits_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait Foo {}
|
||||
trait Bar<T> {}
|
||||
@ -2028,7 +2028,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait Foo<T> {}
|
||||
struct S {}
|
||||
@ -2088,7 +2088,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_dyn_return_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo {}
|
||||
struct S;
|
||||
@ -2156,7 +2156,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_dyn_arg_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait Foo {}
|
||||
fn foo(ar<|>g: &dyn Foo) {}
|
||||
@ -2196,7 +2196,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_generic_dyn_arg_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait Foo<T> {}
|
||||
struct S {}
|
||||
@ -2256,7 +2256,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_goto_type_action_links_order() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /lib.rs
|
||||
trait ImplTrait<T> {}
|
||||
trait DynTrait<T> {}
|
||||
@ -2357,7 +2357,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||
#[test]
|
||||
fn test_hover_associated_type_has_goto_type_action() {
|
||||
let (_, actions) = check_hover_result(
|
||||
"
|
||||
r"
|
||||
//- /main.rs
|
||||
trait Foo {
|
||||
type Item;
|
||||
|
@ -11,7 +11,7 @@ fn test_derive_serialize_proc_macro() {
|
||||
"serde_derive",
|
||||
"Serialize",
|
||||
"1.0",
|
||||
r##"struct Foo {}"##,
|
||||
r"struct Foo {}",
|
||||
include_str!("fixtures/test_serialize_proc_macro.txt"),
|
||||
);
|
||||
}
|
||||
@ -22,9 +22,7 @@ fn test_derive_serialize_proc_macro_failed() {
|
||||
"serde_derive",
|
||||
"Serialize",
|
||||
"1.0",
|
||||
r##"
|
||||
struct {}
|
||||
"##,
|
||||
r"struct {}",
|
||||
r##"
|
||||
SUBTREE $
|
||||
IDENT compile_error 4294967295
|
||||
|
@ -44,12 +44,12 @@ pub fn assert_expand(
|
||||
crate_name: &str,
|
||||
macro_name: &str,
|
||||
version: &str,
|
||||
fixture: &str,
|
||||
ra_fixture: &str,
|
||||
expect: &str,
|
||||
) {
|
||||
let path = fixtures::dylib_path(crate_name, version);
|
||||
let expander = dylib::Expander::new(&path).unwrap();
|
||||
let fixture = parse_string(fixture).unwrap();
|
||||
let fixture = parse_string(ra_fixture).unwrap();
|
||||
|
||||
let res = expander.expand(macro_name, &fixture.subtree, None).unwrap();
|
||||
assert_eq_text!(&format!("{:?}", res), &expect.trim());
|
||||
|
Loading…
Reference in New Issue
Block a user