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