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 | |
parent | 15b16917fcd55068d9aba3d4b5d87763ec5deb69 (diff) |
Move rendering tests to the render module
Diffstat (limited to 'crates/completion/src/render')
-rw-r--r-- | crates/completion/src/render/enum_variant.rs | 74 | ||||
-rw-r--r-- | crates/completion/src/render/function.rs | 210 | ||||
-rw-r--r-- | crates/completion/src/render/macro_.rs | 90 |
3 files changed, 374 insertions, 0 deletions
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 26cfdfeea..bc96cc303 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs | |||
@@ -93,3 +93,77 @@ impl<'a> EnumVariantRender<'a> { | |||
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | |||
97 | #[cfg(test)] | ||
98 | mod tests { | ||
99 | use test_utils::mark; | ||
100 | |||
101 | use crate::test_utils::check_edit; | ||
102 | |||
103 | #[test] | ||
104 | fn inserts_parens_for_tuple_enums() { | ||
105 | mark::check!(inserts_parens_for_tuple_enums); | ||
106 | check_edit( | ||
107 | "Some", | ||
108 | r#" | ||
109 | enum Option<T> { Some(T), None } | ||
110 | use Option::*; | ||
111 | fn main() -> Option<i32> { | ||
112 | Som<|> | ||
113 | } | ||
114 | "#, | ||
115 | r#" | ||
116 | enum Option<T> { Some(T), None } | ||
117 | use Option::*; | ||
118 | fn main() -> Option<i32> { | ||
119 | Some($0) | ||
120 | } | ||
121 | "#, | ||
122 | ); | ||
123 | check_edit( | ||
124 | "Some", | ||
125 | r#" | ||
126 | enum Option<T> { Some(T), None } | ||
127 | use Option::*; | ||
128 | fn main(value: Option<i32>) { | ||
129 | match value { | ||
130 | Som<|> | ||
131 | } | ||
132 | } | ||
133 | "#, | ||
134 | r#" | ||
135 | enum Option<T> { Some(T), None } | ||
136 | use Option::*; | ||
137 | fn main(value: Option<i32>) { | ||
138 | match value { | ||
139 | Some($0) | ||
140 | } | ||
141 | } | ||
142 | "#, | ||
143 | ); | ||
144 | } | ||
145 | |||
146 | #[test] | ||
147 | fn dont_duplicate_pattern_parens() { | ||
148 | mark::check!(dont_duplicate_pattern_parens); | ||
149 | check_edit( | ||
150 | "Var", | ||
151 | r#" | ||
152 | enum E { Var(i32) } | ||
153 | fn main() { | ||
154 | match E::Var(92) { | ||
155 | E::<|>(92) => (), | ||
156 | } | ||
157 | } | ||
158 | "#, | ||
159 | r#" | ||
160 | enum E { Var(i32) } | ||
161 | fn main() { | ||
162 | match E::Var(92) { | ||
163 | E::Var(92) => (), | ||
164 | } | ||
165 | } | ||
166 | "#, | ||
167 | ); | ||
168 | } | ||
169 | } | ||
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 | } | ||
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 0ad8c03b3..6df121c66 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs | |||
@@ -114,3 +114,93 @@ fn guess_macro_braces(macro_name: &str, docs: &str) -> (&'static str, &'static s | |||
114 | .unwrap(); | 114 | .unwrap(); |
115 | (*bra, *ket) | 115 | (*bra, *ket) |
116 | } | 116 | } |
117 | |||
118 | #[cfg(test)] | ||
119 | mod tests { | ||
120 | use test_utils::mark; | ||
121 | |||
122 | use crate::test_utils::check_edit; | ||
123 | |||
124 | #[test] | ||
125 | fn dont_insert_macro_call_parens_unncessary() { | ||
126 | mark::check!(dont_insert_macro_call_parens_unncessary); | ||
127 | check_edit( | ||
128 | "frobnicate!", | ||
129 | r#" | ||
130 | //- /main.rs crate:main deps:foo | ||
131 | use foo::<|>; | ||
132 | //- /foo/lib.rs crate:foo | ||
133 | #[macro_export] | ||
134 | macro_rules frobnicate { () => () } | ||
135 | "#, | ||
136 | r#" | ||
137 | use foo::frobnicate; | ||
138 | "#, | ||
139 | ); | ||
140 | |||
141 | check_edit( | ||
142 | "frobnicate!", | ||
143 | r#" | ||
144 | macro_rules frobnicate { () => () } | ||
145 | fn main() { frob<|>!(); } | ||
146 | "#, | ||
147 | r#" | ||
148 | macro_rules frobnicate { () => () } | ||
149 | fn main() { frobnicate!(); } | ||
150 | "#, | ||
151 | ); | ||
152 | } | ||
153 | |||
154 | #[test] | ||
155 | fn guesses_macro_braces() { | ||
156 | check_edit( | ||
157 | "vec!", | ||
158 | r#" | ||
159 | /// Creates a [`Vec`] containing the arguments. | ||
160 | /// | ||
161 | /// ``` | ||
162 | /// let v = vec![1, 2, 3]; | ||
163 | /// assert_eq!(v[0], 1); | ||
164 | /// assert_eq!(v[1], 2); | ||
165 | /// assert_eq!(v[2], 3); | ||
166 | /// ``` | ||
167 | macro_rules! vec { () => {} } | ||
168 | |||
169 | fn fn main() { v<|> } | ||
170 | "#, | ||
171 | r#" | ||
172 | /// Creates a [`Vec`] containing the arguments. | ||
173 | /// | ||
174 | /// ``` | ||
175 | /// let v = vec![1, 2, 3]; | ||
176 | /// assert_eq!(v[0], 1); | ||
177 | /// assert_eq!(v[1], 2); | ||
178 | /// assert_eq!(v[2], 3); | ||
179 | /// ``` | ||
180 | macro_rules! vec { () => {} } | ||
181 | |||
182 | fn fn main() { vec![$0] } | ||
183 | "#, | ||
184 | ); | ||
185 | |||
186 | check_edit( | ||
187 | "foo!", | ||
188 | r#" | ||
189 | /// Foo | ||
190 | /// | ||
191 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
192 | /// call as `let _=foo! { hello world };` | ||
193 | macro_rules! foo { () => {} } | ||
194 | fn main() { <|> } | ||
195 | "#, | ||
196 | r#" | ||
197 | /// Foo | ||
198 | /// | ||
199 | /// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`, | ||
200 | /// call as `let _=foo! { hello world };` | ||
201 | macro_rules! foo { () => {} } | ||
202 | fn main() { foo! {$0} } | ||
203 | "#, | ||
204 | ) | ||
205 | } | ||
206 | } | ||