Colorize more test fixtures

This commit is contained in:
Laurențiu Nicola 2020-07-01 18:08:45 +03:00
parent 87d24e7caa
commit dbb940fa7d
6 changed files with 71 additions and 71 deletions

View file

@ -137,8 +137,8 @@ mod tests {
documentation: &'a str, documentation: &'a str,
} }
fn check_detail_and_documentation(fixture: &str, expected: DetailAndDocumentation) { fn check_detail_and_documentation(ra_fixture: &str, expected: DetailAndDocumentation) {
let (analysis, position) = analysis_and_position(fixture); let (analysis, position) = analysis_and_position(ra_fixture);
let config = CompletionConfig::default(); let config = CompletionConfig::default();
let completions = analysis.completions(&config, position).unwrap().unwrap(); let completions = analysis.completions(&config, position).unwrap().unwrap();
for item in completions { for item in completions {

View file

@ -324,10 +324,10 @@ mod tests {
/// * a diagnostic is produced /// * a diagnostic is produced
/// * this diagnostic touches the input cursor position /// * this diagnostic touches the input cursor position
/// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied /// * 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 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 diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap();
let mut fix = diagnostic.fix.unwrap(); let mut fix = diagnostic.fix.unwrap();
let edit = fix.source_change.source_file_edits.pop().unwrap().edit; 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 /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
/// apply to the file containing the cursor. /// apply to the file containing the cursor.
fn check_no_diagnostic_for_target_file(fixture: &str) { fn check_no_diagnostic_for_target_file(ra_fixture: &str) {
let (analysis, file_position) = analysis_and_position(fixture); let (analysis, file_position) = analysis_and_position(ra_fixture);
let diagnostics = analysis.diagnostics(file_position.file_id).unwrap(); let diagnostics = analysis.diagnostics(file_position.file_id).unwrap();
assert_eq!(diagnostics.len(), 0); assert_eq!(diagnostics.len(), 0);
} }
fn check_no_diagnostic(content: &str) { fn check_no_diagnostic(ra_fixture: &str) {
let (analysis, file_id) = single_file(content); let (analysis, file_id) = single_file(ra_fixture);
let diagnostics = analysis.diagnostics(file_id).unwrap(); let diagnostics = analysis.diagnostics(file_id).unwrap();
assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one"); assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one");
} }
@ -473,7 +473,8 @@ mod tests {
#[test] #[test]
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { 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 //- /main.rs
use core::result::Result::{self, Ok, Err}; use core::result::Result::{self, Ok, Err};
@ -485,13 +486,14 @@ mod tests {
pub mod result { pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) } pub enum Result<T, E> { Ok(T), Err(E) }
} }
"#; ",
check_no_diagnostic_for_target_file(content); );
} }
#[test] #[test]
fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { 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 //- /main.rs
use core::result::Result::{self, Ok, Err}; use core::result::Result::{self, Ok, Err};
@ -508,8 +510,8 @@ mod tests {
pub mod result { pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) } pub enum Result<T, E> { Ok(T), Err(E) }
} }
"#; ",
check_no_diagnostic_for_target_file(content); );
} }
#[test] #[test]
@ -618,7 +620,8 @@ mod tests {
#[test] #[test]
fn test_fill_struct_fields_no_diagnostic() { fn test_fill_struct_fields_no_diagnostic() {
let content = r" check_no_diagnostic(
r"
struct TestStruct { struct TestStruct {
one: i32, one: i32,
two: i64, two: i64,
@ -628,14 +631,14 @@ mod tests {
let one = 1; let one = 1;
let s = TestStruct{ one, two: 2 }; let s = TestStruct{ one, two: 2 };
} }
"; ",
);
check_no_diagnostic(content);
} }
#[test] #[test]
fn test_fill_struct_fields_no_diagnostic_on_spread() { fn test_fill_struct_fields_no_diagnostic_on_spread() {
let content = r" check_no_diagnostic(
r"
struct TestStruct { struct TestStruct {
one: i32, one: i32,
two: i64, two: i64,
@ -645,9 +648,8 @@ mod tests {
let one = 1; let one = 1;
let s = TestStruct{ ..a }; let s = TestStruct{ ..a };
} }
"; ",
);
check_no_diagnostic(content);
} }
#[test] #[test]

View file

@ -55,8 +55,8 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
mod tests { mod tests {
use crate::mock_analysis::analysis_and_position; use crate::mock_analysis::analysis_and_position;
fn check_goto(fixture: &str, expected: &str) { fn check_goto(ra_fixture: &str, expected: &str) {
let (analysis, pos) = analysis_and_position(fixture); let (analysis, pos) = analysis_and_position(ra_fixture);
let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info; let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info;
assert_eq!(navs.len(), 1); assert_eq!(navs.len(), 1);
@ -67,7 +67,7 @@ mod tests {
#[test] #[test]
fn goto_type_definition_works_simple() { fn goto_type_definition_works_simple() {
check_goto( check_goto(
" r"
//- /lib.rs //- /lib.rs
struct Foo; struct Foo;
fn foo() { fn foo() {
@ -82,7 +82,7 @@ mod tests {
#[test] #[test]
fn goto_type_definition_works_simple_ref() { fn goto_type_definition_works_simple_ref() {
check_goto( check_goto(
" r"
//- /lib.rs //- /lib.rs
struct Foo; struct Foo;
fn foo() { fn foo() {
@ -97,7 +97,7 @@ mod tests {
#[test] #[test]
fn goto_type_definition_works_through_macro() { fn goto_type_definition_works_through_macro() {
check_goto( check_goto(
" r"
//- /lib.rs //- /lib.rs
macro_rules! id { macro_rules! id {
($($tt:tt)*) => { $($tt)* } ($($tt:tt)*) => { $($tt)* }
@ -116,7 +116,7 @@ mod tests {
#[test] #[test]
fn goto_type_definition_for_param() { fn goto_type_definition_for_param() {
check_goto( check_goto(
" r"
//- /lib.rs //- /lib.rs
struct Foo; struct Foo;
fn foo(<|>f: Foo) {} fn foo(<|>f: Foo) {}
@ -128,7 +128,7 @@ mod tests {
#[test] #[test]
fn goto_type_definition_for_tuple_field() { fn goto_type_definition_for_tuple_field() {
check_goto( check_goto(
" r"
//- /lib.rs //- /lib.rs
struct Foo; struct Foo;
struct Bar(Foo); struct Bar(Foo);

View file

@ -417,8 +417,8 @@ mod tests {
assert_eq!(offset, position.into()); assert_eq!(offset, position.into());
} }
fn check_hover_result(fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) { fn check_hover_result(ra_fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) {
let (analysis, position) = analysis_and_position(fixture); let (analysis, position) = analysis_and_position(ra_fixture);
let hover = analysis.hover(position).unwrap().unwrap(); let hover = analysis.hover(position).unwrap().unwrap();
let mut results = Vec::from(hover.info.results()); let mut results = Vec::from(hover.info.results());
results.sort(); results.sort();
@ -435,8 +435,8 @@ mod tests {
(content[hover.range].to_string(), hover.info.actions().to_vec()) (content[hover.range].to_string(), hover.info.actions().to_vec())
} }
fn check_hover_no_result(fixture: &str) { fn check_hover_no_result(ra_fixture: &str) {
let (analysis, position) = analysis_and_position(fixture); let (analysis, position) = analysis_and_position(ra_fixture);
assert!(analysis.hover(position).unwrap().is_none()); assert!(analysis.hover(position).unwrap().is_none());
} }
@ -923,7 +923,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_through_macro() { fn test_hover_through_macro() {
let (hover_on, _) = check_hover_result( let (hover_on, _) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
macro_rules! id { macro_rules! id {
($($tt:tt)*) => { $($tt)* } ($($tt:tt)*) => { $($tt)* }
@ -944,7 +944,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_through_expr_in_macro() { fn test_hover_through_expr_in_macro() {
let (hover_on, _) = check_hover_result( let (hover_on, _) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
macro_rules! id { macro_rules! id {
($($tt:tt)*) => { $($tt)* } ($($tt:tt)*) => { $($tt)* }
@ -962,7 +962,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_through_expr_in_macro_recursive() { fn test_hover_through_expr_in_macro_recursive() {
let (hover_on, _) = check_hover_result( let (hover_on, _) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
macro_rules! id_deep { macro_rules! id_deep {
($($tt:tt)*) => { $($tt)* } ($($tt:tt)*) => { $($tt)* }
@ -983,7 +983,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_through_func_in_macro_recursive() { fn test_hover_through_func_in_macro_recursive() {
let (hover_on, _) = check_hover_result( let (hover_on, _) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
macro_rules! id_deep { macro_rules! id_deep {
($($tt:tt)*) => { $($tt)* } ($($tt:tt)*) => { $($tt)* }
@ -1026,7 +1026,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_through_assert_macro() { fn test_hover_through_assert_macro() {
let (hover_on, _) = check_hover_result( let (hover_on, _) = check_hover_result(
r#" r"
//- /lib.rs //- /lib.rs
#[rustc_builtin_macro] #[rustc_builtin_macro]
macro_rules! assert {} macro_rules! assert {}
@ -1035,7 +1035,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
fn foo() { fn foo() {
assert!(ba<|>r()); assert!(ba<|>r());
} }
"#, ",
&["fn bar() -> bool"], &["fn bar() -> bool"],
); );
@ -1077,14 +1077,14 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_function_show_qualifiers() { fn test_hover_function_show_qualifiers() {
check_hover_result( check_hover_result(
" r"
//- /lib.rs //- /lib.rs
async fn foo<|>() {} async fn foo<|>() {}
", ",
&["async fn foo()"], &["async fn foo()"],
); );
check_hover_result( check_hover_result(
" r"
//- /lib.rs //- /lib.rs
pub const unsafe fn foo<|>() {} pub const unsafe fn foo<|>() {}
", ",
@ -1102,7 +1102,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_trait_show_qualifiers() { fn test_hover_trait_show_qualifiers() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
unsafe trait foo<|>() {} unsafe trait foo<|>() {}
", ",
@ -1114,7 +1114,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_mod_with_same_name_as_function() { fn test_hover_mod_with_same_name_as_function() {
check_hover_result( check_hover_result(
" r"
//- /lib.rs //- /lib.rs
use self::m<|>y::Bar; use self::m<|>y::Bar;
@ -1237,7 +1237,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_trait_has_impl_action() { fn test_hover_trait_has_impl_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait foo<|>() {} trait foo<|>() {}
", ",
@ -1249,7 +1249,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_struct_has_impl_action() { fn test_hover_struct_has_impl_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
struct foo<|>() {} struct foo<|>() {}
", ",
@ -1261,7 +1261,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_union_has_impl_action() { fn test_hover_union_has_impl_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
union foo<|>() {} union foo<|>() {}
", ",
@ -1273,7 +1273,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_enum_has_impl_action() { fn test_hover_enum_has_impl_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
enum foo<|>() { enum foo<|>() {
A, A,
@ -1288,7 +1288,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_test_has_action() { fn test_hover_test_has_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
#[test] #[test]
fn foo_<|>test() {} fn foo_<|>test() {}
@ -1332,7 +1332,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_test_mod_has_action() { fn test_hover_test_mod_has_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
mod tests<|> { mod tests<|> {
#[test] #[test]
@ -1373,7 +1373,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_struct_has_goto_type_action() { fn test_hover_struct_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
struct S{ f1: u32 } struct S{ f1: u32 }
@ -1416,7 +1416,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_generic_struct_has_goto_type_actions() { fn test_hover_generic_struct_has_goto_type_actions() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
struct Arg(u32); struct Arg(u32);
struct S<T>{ f1: T } struct S<T>{ f1: T }
@ -1479,7 +1479,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_generic_struct_has_flattened_goto_type_actions() { fn test_hover_generic_struct_has_flattened_goto_type_actions() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
struct Arg(u32); struct Arg(u32);
struct S<T>{ f1: T } struct S<T>{ f1: T }
@ -1542,7 +1542,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_tuple_has_goto_type_actions() { fn test_hover_tuple_has_goto_type_actions() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
struct A(u32); struct A(u32);
struct B(u32); struct B(u32);
@ -1627,7 +1627,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_return_impl_trait_has_goto_type_action() { fn test_hover_return_impl_trait_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo {} trait Foo {}
@ -1672,7 +1672,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_generic_return_impl_trait_has_goto_type_action() { fn test_hover_generic_return_impl_trait_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo<T> {} trait Foo<T> {}
struct S; struct S;
@ -1737,7 +1737,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_return_impl_traits_has_goto_type_action() { fn test_hover_return_impl_traits_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo {} trait Foo {}
trait Bar {} trait Bar {}
@ -1802,7 +1802,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_generic_return_impl_traits_has_goto_type_action() { fn test_hover_generic_return_impl_traits_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo<T> {} trait Foo<T> {}
trait Bar<T> {} trait Bar<T> {}
@ -1907,7 +1907,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_arg_impl_trait_has_goto_type_action() { fn test_hover_arg_impl_trait_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait Foo {} trait Foo {}
fn foo(ar<|>g: &impl Foo) {} fn foo(ar<|>g: &impl Foo) {}
@ -1947,7 +1947,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_arg_impl_traits_has_goto_type_action() { fn test_hover_arg_impl_traits_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait Foo {} trait Foo {}
trait Bar<T> {} trait Bar<T> {}
@ -2028,7 +2028,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_arg_generic_impl_trait_has_goto_type_action() { fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait Foo<T> {} trait Foo<T> {}
struct S {} struct S {}
@ -2088,7 +2088,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_dyn_return_has_goto_type_action() { fn test_hover_dyn_return_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo {} trait Foo {}
struct S; struct S;
@ -2156,7 +2156,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_dyn_arg_has_goto_type_action() { fn test_hover_dyn_arg_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait Foo {} trait Foo {}
fn foo(ar<|>g: &dyn Foo) {} fn foo(ar<|>g: &dyn Foo) {}
@ -2196,7 +2196,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_generic_dyn_arg_has_goto_type_action() { fn test_hover_generic_dyn_arg_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait Foo<T> {} trait Foo<T> {}
struct S {} struct S {}
@ -2256,7 +2256,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_goto_type_action_links_order() { fn test_hover_goto_type_action_links_order() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /lib.rs //- /lib.rs
trait ImplTrait<T> {} trait ImplTrait<T> {}
trait DynTrait<T> {} trait DynTrait<T> {}
@ -2357,7 +2357,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test] #[test]
fn test_hover_associated_type_has_goto_type_action() { fn test_hover_associated_type_has_goto_type_action() {
let (_, actions) = check_hover_result( let (_, actions) = check_hover_result(
" r"
//- /main.rs //- /main.rs
trait Foo { trait Foo {
type Item; type Item;

View file

@ -11,7 +11,7 @@ fn test_derive_serialize_proc_macro() {
"serde_derive", "serde_derive",
"Serialize", "Serialize",
"1.0", "1.0",
r##"struct Foo {}"##, r"struct Foo {}",
include_str!("fixtures/test_serialize_proc_macro.txt"), include_str!("fixtures/test_serialize_proc_macro.txt"),
); );
} }
@ -22,9 +22,7 @@ fn test_derive_serialize_proc_macro_failed() {
"serde_derive", "serde_derive",
"Serialize", "Serialize",
"1.0", "1.0",
r##" r"struct {}",
struct {}
"##,
r##" r##"
SUBTREE $ SUBTREE $
IDENT compile_error 4294967295 IDENT compile_error 4294967295

View file

@ -44,12 +44,12 @@ pub fn assert_expand(
crate_name: &str, crate_name: &str,
macro_name: &str, macro_name: &str,
version: &str, version: &str,
fixture: &str, ra_fixture: &str,
expect: &str, expect: &str,
) { ) {
let path = fixtures::dylib_path(crate_name, version); let path = fixtures::dylib_path(crate_name, version);
let expander = dylib::Expander::new(&path).unwrap(); 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(); let res = expander.expand(macro_name, &fixture.subtree, None).unwrap();
assert_eq_text!(&format!("{:?}", res), &expect.trim()); assert_eq_text!(&format!("{:?}", res), &expect.trim());