6888: Use standard test style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-12-15 12:34:37 +00:00 committed by GitHub
commit 435d46b183
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ use rustc_hash::FxHashMap;
use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct};
use ide_db::RootDatabase; use ide_db::RootDatabase;
use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
use test_utils::mark;
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, AssistKind, Assists};
@ -38,6 +39,7 @@ fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
}); });
if sorted_fields == fields { if sorted_fields == fields {
mark::hit!(reorder_sorted_fields);
return None; return None;
} }
@ -107,22 +109,25 @@ fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashM
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use test_utils::mark;
use crate::tests::{check_assist, check_assist_not_applicable}; use crate::tests::{check_assist, check_assist_not_applicable};
use super::*; use super::*;
#[test] #[test]
fn not_applicable_if_sorted() { fn reorder_sorted_fields() {
mark::check!(reorder_sorted_fields);
check_assist_not_applicable( check_assist_not_applicable(
reorder_fields, reorder_fields,
r#" r#"
struct Foo { struct Foo {
foo: i32, foo: i32,
bar: i32, bar: i32,
} }
const test: Foo = <|>Foo { foo: 0, bar: 0 }; const test: Foo = <|>Foo { foo: 0, bar: 0 };
"#, "#,
) )
} }
@ -131,9 +136,9 @@ mod tests {
check_assist_not_applicable( check_assist_not_applicable(
reorder_fields, reorder_fields,
r#" r#"
struct Foo {}; struct Foo {};
const test: Foo = <|>Foo {} const test: Foo = <|>Foo {}
"#, "#,
) )
} }
@ -142,13 +147,13 @@ mod tests {
check_assist( check_assist(
reorder_fields, reorder_fields,
r#" r#"
struct Foo {foo: i32, bar: i32}; struct Foo {foo: i32, bar: i32};
const test: Foo = <|>Foo {bar: 0, foo: 1} const test: Foo = <|>Foo {bar: 0, foo: 1}
"#, "#,
r#" r#"
struct Foo {foo: i32, bar: i32}; struct Foo {foo: i32, bar: i32};
const test: Foo = Foo {foo: 1, bar: 0} const test: Foo = Foo {foo: 1, bar: 0}
"#, "#,
) )
} }
@ -157,25 +162,25 @@ mod tests {
check_assist( check_assist(
reorder_fields, reorder_fields,
r#" r#"
struct Foo { foo: i64, bar: i64, baz: i64 } struct Foo { foo: i64, bar: i64, baz: i64 }
fn f(f: Foo) -> { fn f(f: Foo) -> {
match f { match f {
<|>Foo { baz: 0, ref mut bar, .. } => (), <|>Foo { baz: 0, ref mut bar, .. } => (),
_ => () _ => ()
} }
} }
"#, "#,
r#" r#"
struct Foo { foo: i64, bar: i64, baz: i64 } struct Foo { foo: i64, bar: i64, baz: i64 }
fn f(f: Foo) -> { fn f(f: Foo) -> {
match f { match f {
Foo { ref mut bar, baz: 0, .. } => (), Foo { ref mut bar, baz: 0, .. } => (),
_ => () _ => ()
} }
} }
"#, "#,
) )
} }
@ -184,39 +189,39 @@ mod tests {
check_assist( check_assist(
reorder_fields, reorder_fields,
r#" r#"
struct Foo { struct Foo {
foo: String, foo: String,
bar: String, bar: String,
} }
impl Foo { impl Foo {
fn new() -> Foo { fn new() -> Foo {
let foo = String::new(); let foo = String::new();
<|>Foo { <|>Foo {
bar: foo.clone(), bar: foo.clone(),
extra: "Extra field", extra: "Extra field",
foo, foo,
} }
} }
} }
"#, "#,
r#" r#"
struct Foo { struct Foo {
foo: String, foo: String,
bar: String, bar: String,
} }
impl Foo { impl Foo {
fn new() -> Foo { fn new() -> Foo {
let foo = String::new(); let foo = String::new();
Foo { Foo {
foo, foo,
bar: foo.clone(), bar: foo.clone(),
extra: "Extra field", extra: "Extra field",
} }
} }
} }
"#, "#,
) )
} }
} }