aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-04 13:53:43 +0100
committerAleksey Kladov <[email protected]>2020-07-04 13:53:43 +0100
commit03ca33406e983e7748deab09c7677c7f4cdaeeb7 (patch)
tree01bd57ef9cffcc910d9729ebc59b7205fd2c3c8b /crates/ra_ide/src/completion
parent9f754e0518e7f2860891079a117a3e4bc6f4a8fd (diff)
Modernize tests
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_fn_param.rs124
1 files changed, 60 insertions, 64 deletions
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)
54 54
55#[cfg(test)] 55#[cfg(test)]
56mod tests { 56mod tests {
57 use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; 57 use expect::{expect, Expect};
58 use insta::assert_debug_snapshot;
59 58
60 fn do_magic_completion(code: &str) -> Vec<CompletionItem> { 59 use crate::completion::{test_utils::do_completion, CompletionKind};
61 do_completion(code, CompletionKind::Magic) 60
61 fn check(ra_fixture: &str, expect: Expect) {
62 let actual = do_completion(ra_fixture, CompletionKind::Magic);
63 expect.assert_debug_eq(&actual);
62 } 64 }
63 65
64 #[test] 66 #[test]
65 fn test_param_completion_last_param() { 67 fn test_param_completion_last_param() {
66 assert_debug_snapshot!( 68 check(
67 do_magic_completion( 69 r#"
68 r" 70fn foo(file_id: FileId) {}
69 fn foo(file_id: FileId) {} 71fn bar(file_id: FileId) {}
70 fn bar(file_id: FileId) {} 72fn baz(file<|>) {}
71 fn baz(file<|>) {} 73"#,
72 ", 74 expect![[r#"
73 ), 75 [
74 @r###" 76 CompletionItem {
75 [ 77 label: "file_id: FileId",
76 CompletionItem { 78 source_range: 61..65,
77 label: "file_id: FileId", 79 delete: 61..65,
78 source_range: 61..65, 80 insert: "file_id: FileId",
79 delete: 61..65, 81 lookup: "file_id",
80 insert: "file_id: FileId", 82 },
81 lookup: "file_id", 83 ]
82 }, 84 "#]],
83 ]
84 "###
85 ); 85 );
86 } 86 }
87 87
88 #[test] 88 #[test]
89 fn test_param_completion_nth_param() { 89 fn test_param_completion_nth_param() {
90 assert_debug_snapshot!( 90 check(
91 do_magic_completion( 91 r#"
92 r" 92fn foo(file_id: FileId) {}
93 fn foo(file_id: FileId) {} 93fn bar(file_id: FileId) {}
94 fn bar(file_id: FileId) {} 94fn baz(file<|>, x: i32) {}
95 fn baz(file<|>, x: i32) {} 95"#,
96 ", 96 expect![[r#"
97 ), 97 [
98 @r###" 98 CompletionItem {
99 [ 99 label: "file_id: FileId",
100 CompletionItem { 100 source_range: 61..65,
101 label: "file_id: FileId", 101 delete: 61..65,
102 source_range: 61..65, 102 insert: "file_id: FileId",
103 delete: 61..65, 103 lookup: "file_id",
104 insert: "file_id: FileId", 104 },
105 lookup: "file_id", 105 ]
106 }, 106 "#]],
107 ]
108 "###
109 ); 107 );
110 } 108 }
111 109
112 #[test] 110 #[test]
113 fn test_param_completion_trait_param() { 111 fn test_param_completion_trait_param() {
114 assert_debug_snapshot!( 112 check(
115 do_magic_completion( 113 r#"
116 r" 114pub(crate) trait SourceRoot {
117 pub(crate) trait SourceRoot { 115 pub fn contains(&self, file_id: FileId) -> bool;
118 pub fn contains(&self, file_id: FileId) -> bool; 116 pub fn module_map(&self) -> &ModuleMap;
119 pub fn module_map(&self) -> &ModuleMap; 117 pub fn lines(&self, file_id: FileId) -> &LineIndex;
120 pub fn lines(&self, file_id: FileId) -> &LineIndex; 118 pub fn syntax(&self, file<|>)
121 pub fn syntax(&self, file<|>) 119}
122 } 120"#,
123 ", 121 expect![[r#"
124 ), 122 [
125 @r###" 123 CompletionItem {
126 [ 124 label: "file_id: FileId",
127 CompletionItem { 125 source_range: 208..212,
128 label: "file_id: FileId", 126 delete: 208..212,
129 source_range: 208..212, 127 insert: "file_id: FileId",
130 delete: 208..212, 128 lookup: "file_id",
131 insert: "file_id: FileId", 129 },
132 lookup: "file_id", 130 ]
133 }, 131 "#]],
134 ]
135 "###
136 ); 132 );
137 } 133 }
138} 134}