aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Ellison <[email protected]>2019-07-28 11:45:03 +0100
committerPhil Ellison <[email protected]>2019-07-28 11:45:03 +0100
commit69244a6e18b3b53afaa0ee8073af52d93b983a86 (patch)
treefe52d2ecf2e771e1be2ed05bc9a45d48335e6bc2
parent460423e66c7a8d48084813c0d592066b4bef3e85 (diff)
Inline snapshots for all tests in complete_snippet, remove now-unused check_completion
-rw-r--r--crates/ra_ide_api/src/completion.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_snippet.rs75
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs7
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path.snap5
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path2.snap5
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_expressions.snap22
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_items.snap23
7 files changed, 58 insertions, 81 deletions
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;
16use ra_db::SourceDatabase; 16use ra_db::SourceDatabase;
17 17
18#[cfg(test)] 18#[cfg(test)]
19use crate::completion::completion_item::{check_completion, do_completion}; 19use crate::completion::completion_item::do_completion;
20use crate::{ 20use crate::{
21 completion::{ 21 completion::{
22 completion_context::CompletionContext, 22 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}() {
39 39
40#[cfg(test)] 40#[cfg(test)]
41mod tests { 41mod tests {
42 use crate::completion::{check_completion, CompletionKind}; 42 use crate::completion::{do_completion, CompletionItem, CompletionKind};
43 use insta::assert_debug_snapshot_matches;
43 44
44 fn check_snippet_completion(name: &str, code: &str) { 45 fn do_snippet_completion(code: &str) -> Vec<CompletionItem> {
45 check_completion(name, code, CompletionKind::Snippet); 46 do_completion(code, CompletionKind::Snippet)
46 } 47 }
47 48
48 #[test] 49 #[test]
49 fn completes_snippets_in_expressions() { 50 fn completes_snippets_in_expressions() {
50 check_snippet_completion("snippets_in_expressions", r"fn foo(x: i32) { <|> }"); 51 assert_debug_snapshot_matches!(
52 do_snippet_completion(r"fn foo(x: i32) { <|> }"),
53@r#"[
54 CompletionItem {
55 label: "pd",
56 source_range: [17; 17),
57 delete: [17; 17),
58 insert: "eprintln!(\"$0 = {:?}\", $0);",
59 kind: Snippet,
60 },
61 CompletionItem {
62 label: "ppd",
63 source_range: [17; 17),
64 delete: [17; 17),
65 insert: "eprintln!(\"$0 = {:#?}\", $0);",
66 kind: Snippet,
67 },
68]"#
69 );
51 } 70 }
52 71
53 #[test] 72 #[test]
54 fn should_not_complete_snippets_in_path() { 73 fn should_not_complete_snippets_in_path() {
55 check_snippet_completion( 74 assert_debug_snapshot_matches!(
56 "should_not_complete_snippets_in_path", 75 do_snippet_completion(r"fn foo(x: i32) { ::foo<|> }"),
57 r"fn foo(x: i32) { ::foo<|> }", 76@r#"[]"#
58 ); 77 );
59 check_snippet_completion( 78 assert_debug_snapshot_matches!(
60 "should_not_complete_snippets_in_path2", 79 do_snippet_completion(r"fn foo(x: i32) { ::<|> }"),
61 r"fn foo(x: i32) { ::<|> }", 80@r#"[]"#
62 ); 81 );
63 } 82 }
64 83
65 #[test] 84 #[test]
66 fn completes_snippets_in_items() { 85 fn completes_snippets_in_items() {
67 check_snippet_completion( 86 assert_debug_snapshot_matches!(
68 "snippets_in_items", 87 do_snippet_completion(
69 r" 88 r"
70 #[cfg(test)] 89 #[cfg(test)]
71 mod tests { 90 mod tests {
72 <|> 91 <|>
73 } 92 }
74 ", 93 "
94 ),
95@r###"
96 ⋮[
97 ⋮ CompletionItem {
98 ⋮ label: "Test function",
99 ⋮ source_range: [78; 78),
100 ⋮ delete: [78; 78),
101 ⋮ insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
102 ⋮ kind: Snippet,
103 ⋮ lookup: "tfn",
104 ⋮ },
105 ⋮ CompletionItem {
106 ⋮ label: "pub(crate)",
107 ⋮ source_range: [78; 78),
108 ⋮ delete: [78; 78),
109 ⋮ insert: "pub(crate) $0",
110 ⋮ kind: Snippet,
111 ⋮ },
112 ⋮]
113 "###
75 ); 114 );
76 } 115 }
77} 116}
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<CompletionI
299 kind_completions.sort_by_key(|c| c.label.clone()); 299 kind_completions.sort_by_key(|c| c.label.clone());
300 kind_completions 300 kind_completions
301} 301}
302
303#[cfg(test)]
304pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) {
305 use insta::assert_debug_snapshot_matches;
306 let kind_completions = do_completion(code, kind);
307 assert_debug_snapshot_matches!(test_name, kind_completions);
308}
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path.snap
deleted file mode 100644
index cb3278edf..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path.snap
+++ /dev/null
@@ -1,5 +0,0 @@
1Created: 2019-01-23T05:19:36.475253+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/completion/completion_item.rs
4
5[]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path2.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path2.snap
deleted file mode 100644
index 62c8e3de9..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__should_not_complete_snippets_in_path2.snap
+++ /dev/null
@@ -1,5 +0,0 @@
1Created: 2019-01-23T05:19:36.476869+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/completion/completion_item.rs
4
5[]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_expressions.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_expressions.snap
deleted file mode 100644
index 6f41bf76f..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_expressions.snap
+++ /dev/null
@@ -1,22 +0,0 @@
1---
2created: "2019-05-23T22:23:35.141901047Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "pd",
10 source_range: [17; 17),
11 delete: [17; 17),
12 insert: "eprintln!(\"$0 = {:?}\", $0);",
13 kind: Snippet,
14 },
15 CompletionItem {
16 label: "ppd",
17 source_range: [17; 17),
18 delete: [17; 17),
19 insert: "eprintln!(\"$0 = {:#?}\", $0);",
20 kind: Snippet,
21 },
22]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_items.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_items.snap
deleted file mode 100644
index 1eb0adebe..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__snippets_in_items.snap
+++ /dev/null
@@ -1,23 +0,0 @@
1---
2created: "2019-05-23T22:23:35.149234118Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "Test function",
10 source_range: [66; 66),
11 delete: [66; 66),
12 insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
13 kind: Snippet,
14 lookup: "tfn",
15 },
16 CompletionItem {
17 label: "pub(crate)",
18 source_range: [66; 66),
19 delete: [66; 66),
20 insert: "pub(crate) $0",
21 kind: Snippet,
22 },
23]