aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-30 18:07:14 +0000
committerJeremy A. Kolb <[email protected]>2018-10-31 19:23:20 +0000
commit05eb489ec58fbcd36f8d68c74e42166b345a3a3f (patch)
tree17083b18fd209334833423728df1a170ea7a3905 /crates/ra_analysis/tests
parentd2bcd1a38636a669d2232156fa29010a82e37a3e (diff)
Useful comments from function signatures
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r--crates/ra_analysis/tests/tests.rs147
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]
189fn test_fn_signature_with_docs_simple() {
190 let (desc, param) = get_signature(
191 r#"
192// test
193fn foo(j: u32) -> u32 {
194 j
195}
196
197fn 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]
212fn 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/// ```
224pub fn add_one(x: i32) -> i32 {
225 x + 1
226}
227
228pub 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(
239r#"Adds one to the number given.
240
241# Examples
242
243```rust
244let five = 5;
245
246assert_eq!(6, my_crate::add_one(5));
247```"#.into()));
248}
249
250#[test]
251fn test_fn_signature_with_docs_impl() {
252 let (desc, param) = get_signature(
253 r#"
254struct addr;
255impl 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
270pub 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(
281r#"Adds one to the number given.
282
283# Examples
284
285```rust
286let five = 5;
287
288assert_eq!(6, my_crate::add_one(5));
289```"#.into()));
290}
291
292#[test]
293fn test_fn_signature_with_docs_from_actix() {
294 let (desc, param) = get_signature(
295 r#"
296pub trait WriteHandler<E>
297where
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
317pub 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(
329r#"Method is called when writer finishes.
330
331By default this method stops actor's `Context`."#.into()));
332}
333
334
188fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { 335fn 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();