From 69244a6e18b3b53afaa0ee8073af52d93b983a86 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 11:45:03 +0100 Subject: Inline snapshots for all tests in complete_snippet, remove now-unused check_completion --- crates/ra_ide_api/src/completion.rs | 2 +- .../ra_ide_api/src/completion/complete_snippet.rs | 75 ++++++++++++++++------ .../ra_ide_api/src/completion/completion_item.rs | 7 -- ...item__should_not_complete_snippets_in_path.snap | 5 -- ...tem__should_not_complete_snippets_in_path2.snap | 5 -- .../completion_item__snippets_in_expressions.snap | 22 ------- .../completion_item__snippets_in_items.snap | 23 ------- 7 files changed, 58 insertions(+), 81 deletions(-) delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path2.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_expressions.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_items.snap (limited to 'crates') diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index 85160358a..a6b68be75 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -16,7 +16,7 @@ mod complete_postfix; use ra_db::SourceDatabase; #[cfg(test)] -use crate::completion::completion_item::{check_completion, do_completion}; +use crate::completion::completion_item::do_completion; use crate::{ completion::{ completion_context::CompletionContext, diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs index d2d364b57..063b69319 100644 --- a/crates/ra_ide_api/src/completion/complete_snippet.rs +++ b/crates/ra_ide_api/src/completion/complete_snippet.rs @@ -39,39 +39,78 @@ fn ${1:feature}() { #[cfg(test)] mod tests { - use crate::completion::{check_completion, CompletionKind}; + use crate::completion::{do_completion, CompletionItem, CompletionKind}; + use insta::assert_debug_snapshot_matches; - fn check_snippet_completion(name: &str, code: &str) { - check_completion(name, code, CompletionKind::Snippet); + fn do_snippet_completion(code: &str) -> Vec { + do_completion(code, CompletionKind::Snippet) } #[test] fn completes_snippets_in_expressions() { - check_snippet_completion("snippets_in_expressions", r"fn foo(x: i32) { <|> }"); + assert_debug_snapshot_matches!( + do_snippet_completion(r"fn foo(x: i32) { <|> }"), +@r#"[ + CompletionItem { + label: "pd", + source_range: [17; 17), + delete: [17; 17), + insert: "eprintln!(\"$0 = {:?}\", $0);", + kind: Snippet, + }, + CompletionItem { + label: "ppd", + source_range: [17; 17), + delete: [17; 17), + insert: "eprintln!(\"$0 = {:#?}\", $0);", + kind: Snippet, + }, +]"# + ); } #[test] fn should_not_complete_snippets_in_path() { - check_snippet_completion( - "should_not_complete_snippets_in_path", - r"fn foo(x: i32) { ::foo<|> }", + assert_debug_snapshot_matches!( + do_snippet_completion(r"fn foo(x: i32) { ::foo<|> }"), +@r#"[]"# ); - check_snippet_completion( - "should_not_complete_snippets_in_path2", - r"fn foo(x: i32) { ::<|> }", + assert_debug_snapshot_matches!( + do_snippet_completion(r"fn foo(x: i32) { ::<|> }"), +@r#"[]"# ); } #[test] fn completes_snippets_in_items() { - check_snippet_completion( - "snippets_in_items", - r" - #[cfg(test)] - mod tests { - <|> - } - ", + assert_debug_snapshot_matches!( + do_snippet_completion( + r" + #[cfg(test)] + mod tests { + <|> + } + " + ), +@r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "Test function", + ⋮ source_range: [78; 78), + ⋮ delete: [78; 78), + ⋮ insert: "#[test]\nfn ${1:feature}() {\n $0\n}", + ⋮ kind: Snippet, + ⋮ lookup: "tfn", + ⋮ }, + ⋮ CompletionItem { + ⋮ label: "pub(crate)", + ⋮ source_range: [78; 78), + ⋮ delete: [78; 78), + ⋮ insert: "pub(crate) $0", + ⋮ kind: Snippet, + ⋮ }, + ⋮] + "### ); } } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index f78c4c877..d787bb69e 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -299,10 +299,3 @@ pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec