diff options
author | Igor Aleksanov <[email protected]> | 2020-11-01 10:36:30 +0000 |
---|---|---|
committer | Igor Aleksanov <[email protected]> | 2020-11-03 07:16:35 +0000 |
commit | 97a504805d4b0cf8b48bc5052453b2b2f3298449 (patch) | |
tree | dd5da407ca9332898107fd51199ea49f396f7590 /crates/completion/src/render/function.rs | |
parent | 15b16917fcd55068d9aba3d4b5d87763ec5deb69 (diff) |
Move rendering tests to the render module
Diffstat (limited to 'crates/completion/src/render/function.rs')
-rw-r--r-- | crates/completion/src/render/function.rs | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index d22081236..cf3852bf6 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs | |||
@@ -81,3 +81,213 @@ impl<'a> FunctionRender<'a> { | |||
81 | } | 81 | } |
82 | } | 82 | } |
83 | } | 83 | } |
84 | |||
85 | #[cfg(test)] | ||
86 | mod tests { | ||
87 | use test_utils::mark; | ||
88 | |||
89 | use crate::{ | ||
90 | test_utils::{check_edit, check_edit_with_config}, | ||
91 | CompletionConfig, | ||
92 | }; | ||
93 | |||
94 | #[test] | ||
95 | fn inserts_parens_for_function_calls() { | ||
96 | mark::check!(inserts_parens_for_function_calls); | ||
97 | check_edit( | ||
98 | "no_args", | ||
99 | r#" | ||
100 | fn no_args() {} | ||
101 | fn main() { no_<|> } | ||
102 | "#, | ||
103 | r#" | ||
104 | fn no_args() {} | ||
105 | fn main() { no_args()$0 } | ||
106 | "#, | ||
107 | ); | ||
108 | |||
109 | check_edit( | ||
110 | "with_args", | ||
111 | r#" | ||
112 | fn with_args(x: i32, y: String) {} | ||
113 | fn main() { with_<|> } | ||
114 | "#, | ||
115 | r#" | ||
116 | fn with_args(x: i32, y: String) {} | ||
117 | fn main() { with_args(${1:x}, ${2:y})$0 } | ||
118 | "#, | ||
119 | ); | ||
120 | |||
121 | check_edit( | ||
122 | "foo", | ||
123 | r#" | ||
124 | struct S; | ||
125 | impl S { | ||
126 | fn foo(&self) {} | ||
127 | } | ||
128 | fn bar(s: &S) { s.f<|> } | ||
129 | "#, | ||
130 | r#" | ||
131 | struct S; | ||
132 | impl S { | ||
133 | fn foo(&self) {} | ||
134 | } | ||
135 | fn bar(s: &S) { s.foo()$0 } | ||
136 | "#, | ||
137 | ); | ||
138 | |||
139 | check_edit( | ||
140 | "foo", | ||
141 | r#" | ||
142 | struct S {} | ||
143 | impl S { | ||
144 | fn foo(&self, x: i32) {} | ||
145 | } | ||
146 | fn bar(s: &S) { | ||
147 | s.f<|> | ||
148 | } | ||
149 | "#, | ||
150 | r#" | ||
151 | struct S {} | ||
152 | impl S { | ||
153 | fn foo(&self, x: i32) {} | ||
154 | } | ||
155 | fn bar(s: &S) { | ||
156 | s.foo(${1:x})$0 | ||
157 | } | ||
158 | "#, | ||
159 | ); | ||
160 | } | ||
161 | |||
162 | #[test] | ||
163 | fn suppress_arg_snippets() { | ||
164 | mark::check!(suppress_arg_snippets); | ||
165 | check_edit_with_config( | ||
166 | CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() }, | ||
167 | "with_args", | ||
168 | r#" | ||
169 | fn with_args(x: i32, y: String) {} | ||
170 | fn main() { with_<|> } | ||
171 | "#, | ||
172 | r#" | ||
173 | fn with_args(x: i32, y: String) {} | ||
174 | fn main() { with_args($0) } | ||
175 | "#, | ||
176 | ); | ||
177 | } | ||
178 | |||
179 | #[test] | ||
180 | fn strips_underscores_from_args() { | ||
181 | check_edit( | ||
182 | "foo", | ||
183 | r#" | ||
184 | fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {} | ||
185 | fn main() { f<|> } | ||
186 | "#, | ||
187 | r#" | ||
188 | fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {} | ||
189 | fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 } | ||
190 | "#, | ||
191 | ); | ||
192 | } | ||
193 | |||
194 | #[test] | ||
195 | fn insert_ref_when_matching_local_in_scope() { | ||
196 | check_edit( | ||
197 | "ref_arg", | ||
198 | r#" | ||
199 | struct Foo {} | ||
200 | fn ref_arg(x: &Foo) {} | ||
201 | fn main() { | ||
202 | let x = Foo {}; | ||
203 | ref_ar<|> | ||
204 | } | ||
205 | "#, | ||
206 | r#" | ||
207 | struct Foo {} | ||
208 | fn ref_arg(x: &Foo) {} | ||
209 | fn main() { | ||
210 | let x = Foo {}; | ||
211 | ref_arg(${1:&x})$0 | ||
212 | } | ||
213 | "#, | ||
214 | ); | ||
215 | } | ||
216 | |||
217 | #[test] | ||
218 | fn insert_mut_ref_when_matching_local_in_scope() { | ||
219 | check_edit( | ||
220 | "ref_arg", | ||
221 | r#" | ||
222 | struct Foo {} | ||
223 | fn ref_arg(x: &mut Foo) {} | ||
224 | fn main() { | ||
225 | let x = Foo {}; | ||
226 | ref_ar<|> | ||
227 | } | ||
228 | "#, | ||
229 | r#" | ||
230 | struct Foo {} | ||
231 | fn ref_arg(x: &mut Foo) {} | ||
232 | fn main() { | ||
233 | let x = Foo {}; | ||
234 | ref_arg(${1:&mut x})$0 | ||
235 | } | ||
236 | "#, | ||
237 | ); | ||
238 | } | ||
239 | |||
240 | #[test] | ||
241 | fn insert_ref_when_matching_local_in_scope_for_method() { | ||
242 | check_edit( | ||
243 | "apply_foo", | ||
244 | r#" | ||
245 | struct Foo {} | ||
246 | struct Bar {} | ||
247 | impl Bar { | ||
248 | fn apply_foo(&self, x: &Foo) {} | ||
249 | } | ||
250 | |||
251 | fn main() { | ||
252 | let x = Foo {}; | ||
253 | let y = Bar {}; | ||
254 | y.<|> | ||
255 | } | ||
256 | "#, | ||
257 | r#" | ||
258 | struct Foo {} | ||
259 | struct Bar {} | ||
260 | impl Bar { | ||
261 | fn apply_foo(&self, x: &Foo) {} | ||
262 | } | ||
263 | |||
264 | fn main() { | ||
265 | let x = Foo {}; | ||
266 | let y = Bar {}; | ||
267 | y.apply_foo(${1:&x})$0 | ||
268 | } | ||
269 | "#, | ||
270 | ); | ||
271 | } | ||
272 | |||
273 | #[test] | ||
274 | fn trim_mut_keyword_in_func_completion() { | ||
275 | check_edit( | ||
276 | "take_mutably", | ||
277 | r#" | ||
278 | fn take_mutably(mut x: &i32) {} | ||
279 | |||
280 | fn main() { | ||
281 | take_m<|> | ||
282 | } | ||
283 | "#, | ||
284 | r#" | ||
285 | fn take_mutably(mut x: &i32) {} | ||
286 | |||
287 | fn main() { | ||
288 | take_mutably(${1:x})$0 | ||
289 | } | ||
290 | "#, | ||
291 | ); | ||
292 | } | ||
293 | } | ||