diff options
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 94e025677..9e2478d9e 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -195,6 +195,153 @@ fn bar() { | |||
195 | assert_eq!(param, Some(1)); | 195 | assert_eq!(param, Some(1)); |
196 | } | 196 | } |
197 | 197 | ||
198 | #[test] | ||
199 | fn test_fn_signature_with_docs_simple() { | ||
200 | let (desc, param) = get_signature( | ||
201 | r#" | ||
202 | // test | ||
203 | fn foo(j: u32) -> u32 { | ||
204 | j | ||
205 | } | ||
206 | |||
207 | fn bar() { | ||
208 | let _ = foo(<|>); | ||
209 | } | ||
210 | "#, | ||
211 | ); | ||
212 | |||
213 | assert_eq!(desc.name, "foo".to_string()); | ||
214 | assert_eq!(desc.params, vec!["j".to_string()]); | ||
215 | assert_eq!(desc.ret_type, Some("-> u32".to_string())); | ||
216 | assert_eq!(param, Some(0)); | ||
217 | assert_eq!(desc.label, "fn foo(j: u32) -> u32".to_string()); | ||
218 | assert_eq!(desc.doc, Some("test".into())); | ||
219 | } | ||
220 | |||
221 | #[test] | ||
222 | fn test_fn_signature_with_docs() { | ||
223 | let (desc, param) = get_signature( | ||
224 | r#" | ||
225 | /// Adds one to the number given. | ||
226 | /// | ||
227 | /// # Examples | ||
228 | /// | ||
229 | /// ``` | ||
230 | /// let five = 5; | ||
231 | /// | ||
232 | /// assert_eq!(6, my_crate::add_one(5)); | ||
233 | /// ``` | ||
234 | pub fn add_one(x: i32) -> i32 { | ||
235 | x + 1 | ||
236 | } | ||
237 | |||
238 | pub fn do() { | ||
239 | add_one(<|> | ||
240 | }"#, | ||
241 | ); | ||
242 | |||
243 | assert_eq!(desc.name, "add_one".to_string()); | ||
244 | assert_eq!(desc.params, vec!["x".to_string()]); | ||
245 | assert_eq!(desc.ret_type, Some("-> i32".to_string())); | ||
246 | assert_eq!(param, Some(0)); | ||
247 | assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string()); | ||
248 | assert_eq!(desc.doc, Some( | ||
249 | r#"Adds one to the number given. | ||
250 | |||
251 | # Examples | ||
252 | |||
253 | ```rust | ||
254 | let five = 5; | ||
255 | |||
256 | assert_eq!(6, my_crate::add_one(5)); | ||
257 | ```"#.into())); | ||
258 | } | ||
259 | |||
260 | #[test] | ||
261 | fn test_fn_signature_with_docs_impl() { | ||
262 | let (desc, param) = get_signature( | ||
263 | r#" | ||
264 | struct addr; | ||
265 | impl addr { | ||
266 | /// Adds one to the number given. | ||
267 | /// | ||
268 | /// # Examples | ||
269 | /// | ||
270 | /// ``` | ||
271 | /// let five = 5; | ||
272 | /// | ||
273 | /// assert_eq!(6, my_crate::add_one(5)); | ||
274 | /// ``` | ||
275 | pub fn add_one(x: i32) -> i32 { | ||
276 | x + 1 | ||
277 | } | ||
278 | } | ||
279 | |||
280 | pub fn do_it() { | ||
281 | addr {}; | ||
282 | addr::add_one(<|>); | ||
283 | }"#); | ||
284 | |||
285 | assert_eq!(desc.name, "add_one".to_string()); | ||
286 | assert_eq!(desc.params, vec!["x".to_string()]); | ||
287 | assert_eq!(desc.ret_type, Some("-> i32".to_string())); | ||
288 | assert_eq!(param, Some(0)); | ||
289 | assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string()); | ||
290 | assert_eq!(desc.doc, Some( | ||
291 | r#"Adds one to the number given. | ||
292 | |||
293 | # Examples | ||
294 | |||
295 | ```rust | ||
296 | let five = 5; | ||
297 | |||
298 | assert_eq!(6, my_crate::add_one(5)); | ||
299 | ```"#.into())); | ||
300 | } | ||
301 | |||
302 | #[test] | ||
303 | fn test_fn_signature_with_docs_from_actix() { | ||
304 | let (desc, param) = get_signature( | ||
305 | r#" | ||
306 | pub trait WriteHandler<E> | ||
307 | where | ||
308 | Self: Actor, | ||
309 | Self::Context: ActorContext, | ||
310 | { | ||
311 | /// Method is called when writer emits error. | ||
312 | /// | ||
313 | /// If this method returns `ErrorAction::Continue` writer processing | ||
314 | /// continues otherwise stream processing stops. | ||
315 | fn error(&mut self, err: E, ctx: &mut Self::Context) -> Running { | ||
316 | Running::Stop | ||
317 | } | ||
318 | |||
319 | /// Method is called when writer finishes. | ||
320 | /// | ||
321 | /// By default this method stops actor's `Context`. | ||
322 | fn finished(&mut self, ctx: &mut Self::Context) { | ||
323 | ctx.stop() | ||
324 | } | ||
325 | } | ||
326 | |||
327 | pub fn foo() { | ||
328 | WriteHandler r; | ||
329 | r.finished(<|>); | ||
330 | } | ||
331 | |||
332 | "#); | ||
333 | |||
334 | assert_eq!(desc.name, "finished".to_string()); | ||
335 | assert_eq!(desc.params, vec!["&mut self".to_string(), "ctx".to_string()]); | ||
336 | assert_eq!(desc.ret_type, None); | ||
337 | assert_eq!(param, Some(1)); | ||
338 | assert_eq!(desc.doc, Some( | ||
339 | r#"Method is called when writer finishes. | ||
340 | |||
341 | By default this method stops actor's `Context`."#.into())); | ||
342 | } | ||
343 | |||
344 | |||
198 | fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { | 345 | fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { |
199 | let (analysis, position) = single_file_with_position(text); | 346 | let (analysis, position) = single_file_with_position(text); |
200 | analysis.find_all_refs(position.file_id, position.offset).unwrap() | 347 | analysis.find_all_refs(position.file_id, position.offset).unwrap() |