From 03ca33406e983e7748deab09c7677c7f4cdaeeb7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 4 Jul 2020 14:53:43 +0200 Subject: Modernize tests --- crates/ra_ide/src/completion/complete_fn_param.rs | 124 +++++++++++----------- 1 file changed, 60 insertions(+), 64 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index f5573ddf7..9fb5c050e 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -54,85 +54,81 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) #[cfg(test)] mod tests { - use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; - use insta::assert_debug_snapshot; + use expect::{expect, Expect}; - fn do_magic_completion(code: &str) -> Vec { - do_completion(code, CompletionKind::Magic) + use crate::completion::{test_utils::do_completion, CompletionKind}; + + fn check(ra_fixture: &str, expect: Expect) { + let actual = do_completion(ra_fixture, CompletionKind::Magic); + expect.assert_debug_eq(&actual); } #[test] fn test_param_completion_last_param() { - assert_debug_snapshot!( - do_magic_completion( - r" - fn foo(file_id: FileId) {} - fn bar(file_id: FileId) {} - fn baz(file<|>) {} - ", - ), - @r###" - [ - CompletionItem { - label: "file_id: FileId", - source_range: 61..65, - delete: 61..65, - insert: "file_id: FileId", - lookup: "file_id", - }, - ] - "### + check( + r#" +fn foo(file_id: FileId) {} +fn bar(file_id: FileId) {} +fn baz(file<|>) {} +"#, + expect![[r#" + [ + CompletionItem { + label: "file_id: FileId", + source_range: 61..65, + delete: 61..65, + insert: "file_id: FileId", + lookup: "file_id", + }, + ] + "#]], ); } #[test] fn test_param_completion_nth_param() { - assert_debug_snapshot!( - do_magic_completion( - r" - fn foo(file_id: FileId) {} - fn bar(file_id: FileId) {} - fn baz(file<|>, x: i32) {} - ", - ), - @r###" - [ - CompletionItem { - label: "file_id: FileId", - source_range: 61..65, - delete: 61..65, - insert: "file_id: FileId", - lookup: "file_id", - }, - ] - "### + check( + r#" +fn foo(file_id: FileId) {} +fn bar(file_id: FileId) {} +fn baz(file<|>, x: i32) {} +"#, + expect![[r#" + [ + CompletionItem { + label: "file_id: FileId", + source_range: 61..65, + delete: 61..65, + insert: "file_id: FileId", + lookup: "file_id", + }, + ] + "#]], ); } #[test] fn test_param_completion_trait_param() { - assert_debug_snapshot!( - do_magic_completion( - r" - pub(crate) trait SourceRoot { - pub fn contains(&self, file_id: FileId) -> bool; - pub fn module_map(&self) -> &ModuleMap; - pub fn lines(&self, file_id: FileId) -> &LineIndex; - pub fn syntax(&self, file<|>) - } - ", - ), - @r###" - [ - CompletionItem { - label: "file_id: FileId", - source_range: 208..212, - delete: 208..212, - insert: "file_id: FileId", - lookup: "file_id", - }, - ] - "### + check( + r#" +pub(crate) trait SourceRoot { + pub fn contains(&self, file_id: FileId) -> bool; + pub fn module_map(&self) -> &ModuleMap; + pub fn lines(&self, file_id: FileId) -> &LineIndex; + pub fn syntax(&self, file<|>) +} +"#, + expect![[r#" + [ + CompletionItem { + label: "file_id: FileId", + source_range: 208..212, + delete: 208..212, + insert: "file_id: FileId", + lookup: "file_id", + }, + ] + "#]], ); } } -- cgit v1.2.3