From c582e52a1be88d4d0465f3eb396640d0b619dedf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Dec 2020 11:51:40 +0300 Subject: Use standard test style --- crates/assists/src/handlers/reorder_fields.rs | 129 +++++++++++++------------- 1 file changed, 67 insertions(+), 62 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/handlers/reorder_fields.rs b/crates/assists/src/handlers/reorder_fields.rs index 7c0f0f44e..fe5574242 100644 --- a/crates/assists/src/handlers/reorder_fields.rs +++ b/crates/assists/src/handlers/reorder_fields.rs @@ -4,6 +4,7 @@ use rustc_hash::FxHashMap; use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; use ide_db::RootDatabase; use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; +use test_utils::mark; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -38,6 +39,7 @@ fn reorder(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { }); if sorted_fields == fields { + mark::hit!(reorder_sorted_fields); return None; } @@ -107,22 +109,25 @@ fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> OptionFoo { foo: 0, bar: 0 }; - "#, +const test: Foo = <|>Foo { foo: 0, bar: 0 }; +"#, ) } @@ -131,9 +136,9 @@ mod tests { check_assist_not_applicable( reorder_fields, r#" - struct Foo {}; - const test: Foo = <|>Foo {} - "#, +struct Foo {}; +const test: Foo = <|>Foo {} +"#, ) } @@ -142,13 +147,13 @@ mod tests { check_assist( reorder_fields, r#" - struct Foo {foo: i32, bar: i32}; - const test: Foo = <|>Foo {bar: 0, foo: 1} - "#, +struct Foo {foo: i32, bar: i32}; +const test: Foo = <|>Foo {bar: 0, foo: 1} +"#, r#" - struct Foo {foo: i32, bar: i32}; - const test: Foo = Foo {foo: 1, bar: 0} - "#, +struct Foo {foo: i32, bar: i32}; +const test: Foo = Foo {foo: 1, bar: 0} +"#, ) } @@ -157,25 +162,25 @@ mod tests { check_assist( reorder_fields, r#" - struct Foo { foo: i64, bar: i64, baz: i64 } +struct Foo { foo: i64, bar: i64, baz: i64 } - fn f(f: Foo) -> { - match f { - <|>Foo { baz: 0, ref mut bar, .. } => (), - _ => () - } - } - "#, +fn f(f: Foo) -> { + match f { + <|>Foo { baz: 0, ref mut bar, .. } => (), + _ => () + } +} +"#, r#" - struct Foo { foo: i64, bar: i64, baz: i64 } +struct Foo { foo: i64, bar: i64, baz: i64 } - fn f(f: Foo) -> { - match f { - Foo { ref mut bar, baz: 0, .. } => (), - _ => () - } - } - "#, +fn f(f: Foo) -> { + match f { + Foo { ref mut bar, baz: 0, .. } => (), + _ => () + } +} +"#, ) } @@ -184,39 +189,39 @@ mod tests { check_assist( reorder_fields, r#" - struct Foo { - foo: String, - bar: String, - } +struct Foo { + foo: String, + bar: String, +} - impl Foo { - fn new() -> Foo { - let foo = String::new(); - <|>Foo { - bar: foo.clone(), - extra: "Extra field", - foo, - } - } - } - "#, +impl Foo { + fn new() -> Foo { + let foo = String::new(); + <|>Foo { + bar: foo.clone(), + extra: "Extra field", + foo, + } + } +} +"#, r#" - struct Foo { - foo: String, - bar: String, - } +struct Foo { + foo: String, + bar: String, +} - impl Foo { - fn new() -> Foo { - let foo = String::new(); - Foo { - foo, - bar: foo.clone(), - extra: "Extra field", - } - } - } - "#, +impl Foo { + fn new() -> Foo { + let foo = String::new(); + Foo { + foo, + bar: foo.clone(), + extra: "Extra field", + } + } +} +"#, ) } } -- cgit v1.2.3