aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests/test/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/tests/test/main.rs')
-rw-r--r--crates/ra_analysis/tests/test/main.rs261
1 files changed, 1 insertions, 260 deletions
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs
index 1f70af12a..2c0735cb5 100644
--- a/crates/ra_analysis/tests/test/main.rs
+++ b/crates/ra_analysis/tests/test/main.rs
@@ -5,14 +5,9 @@ use test_utils::{assert_eq_dbg, assert_eq_text};
5 5
6use ra_analysis::{ 6use ra_analysis::{
7 mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis}, 7 mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis},
8 AnalysisChange, CrateGraph, FileId, FnSignatureInfo, Query 8 AnalysisChange, CrateGraph, FileId, Query
9}; 9};
10 10
11fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
12 let (analysis, position) = single_file_with_position(text);
13 analysis.resolve_callable(position).unwrap().unwrap()
14}
15
16#[test] 11#[test]
17fn test_unresolved_module_diagnostic() { 12fn test_unresolved_module_diagnostic() {
18 let (analysis, file_id) = single_file("mod foo;"); 13 let (analysis, file_id) = single_file("mod foo;");
@@ -99,260 +94,6 @@ fn test_resolve_crate_root() {
99 assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); 94 assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]);
100} 95}
101 96
102#[test]
103fn test_fn_signature_two_args_first() {
104 let (desc, param) = get_signature(
105 r#"fn foo(x: u32, y: u32) -> u32 {x + y}
106fn bar() { foo(<|>3, ); }"#,
107 );
108
109 assert_eq!(desc.name, "foo".to_string());
110 assert_eq!(desc.params, vec!("x".to_string(), "y".to_string()));
111 assert_eq!(desc.ret_type, Some("-> u32".into()));
112 assert_eq!(param, Some(0));
113}
114
115#[test]
116fn test_fn_signature_two_args_second() {
117 let (desc, param) = get_signature(
118 r#"fn foo(x: u32, y: u32) -> u32 {x + y}
119fn bar() { foo(3, <|>); }"#,
120 );
121
122 assert_eq!(desc.name, "foo".to_string());
123 assert_eq!(desc.params, vec!("x".to_string(), "y".to_string()));
124 assert_eq!(desc.ret_type, Some("-> u32".into()));
125 assert_eq!(param, Some(1));
126}
127
128#[test]
129fn test_fn_signature_for_impl() {
130 let (desc, param) = get_signature(
131 r#"struct F; impl F { pub fn new() { F{}} }
132fn bar() {let _ : F = F::new(<|>);}"#,
133 );
134
135 assert_eq!(desc.name, "new".to_string());
136 assert_eq!(desc.params, Vec::<String>::new());
137 assert_eq!(desc.ret_type, None);
138 assert_eq!(param, None);
139}
140
141#[test]
142fn test_fn_signature_for_method_self() {
143 let (desc, param) = get_signature(
144 r#"struct F;
145impl F {
146 pub fn new() -> F{
147 F{}
148 }
149
150 pub fn do_it(&self) {}
151}
152
153fn bar() {
154 let f : F = F::new();
155 f.do_it(<|>);
156}"#,
157 );
158
159 assert_eq!(desc.name, "do_it".to_string());
160 assert_eq!(desc.params, vec!["&self".to_string()]);
161 assert_eq!(desc.ret_type, None);
162 assert_eq!(param, None);
163}
164
165#[test]
166fn test_fn_signature_for_method_with_arg() {
167 let (desc, param) = get_signature(
168 r#"struct F;
169impl F {
170 pub fn new() -> F{
171 F{}
172 }
173
174 pub fn do_it(&self, x: i32) {}
175}
176
177fn bar() {
178 let f : F = F::new();
179 f.do_it(<|>);
180}"#,
181 );
182
183 assert_eq!(desc.name, "do_it".to_string());
184 assert_eq!(desc.params, vec!["&self".to_string(), "x".to_string()]);
185 assert_eq!(desc.ret_type, None);
186 assert_eq!(param, Some(1));
187}
188
189#[test]
190fn test_fn_signature_with_docs_simple() {
191 let (desc, param) = get_signature(
192 r#"
193/// test
194// non-doc-comment
195fn foo(j: u32) -> u32 {
196 j
197}
198
199fn bar() {
200 let _ = foo(<|>);
201}
202"#,
203 );
204
205 assert_eq!(desc.name, "foo".to_string());
206 assert_eq!(desc.params, vec!["j".to_string()]);
207 assert_eq!(desc.ret_type, Some("-> u32".to_string()));
208 assert_eq!(param, Some(0));
209 assert_eq!(desc.label, "fn foo(j: u32) -> u32".to_string());
210 assert_eq!(desc.doc, Some("test".into()));
211}
212
213#[test]
214fn test_fn_signature_with_docs() {
215 let (desc, param) = get_signature(
216 r#"
217/// Adds one to the number given.
218///
219/// # Examples
220///
221/// ```
222/// let five = 5;
223///
224/// assert_eq!(6, my_crate::add_one(5));
225/// ```
226pub fn add_one(x: i32) -> i32 {
227 x + 1
228}
229
230pub fn do() {
231 add_one(<|>
232}"#,
233 );
234
235 assert_eq!(desc.name, "add_one".to_string());
236 assert_eq!(desc.params, vec!["x".to_string()]);
237 assert_eq!(desc.ret_type, Some("-> i32".to_string()));
238 assert_eq!(param, Some(0));
239 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string());
240 assert_eq!(
241 desc.doc,
242 Some(
243 r#"Adds one to the number given.
244
245# Examples
246
247```rust
248let five = 5;
249
250assert_eq!(6, my_crate::add_one(5));
251```"#
252 .into()
253 )
254 );
255}
256
257#[test]
258fn test_fn_signature_with_docs_impl() {
259 let (desc, param) = get_signature(
260 r#"
261struct addr;
262impl addr {
263 /// Adds one to the number given.
264 ///
265 /// # Examples
266 ///
267 /// ```
268 /// let five = 5;
269 ///
270 /// assert_eq!(6, my_crate::add_one(5));
271 /// ```
272 pub fn add_one(x: i32) -> i32 {
273 x + 1
274 }
275}
276
277pub fn do_it() {
278 addr {};
279 addr::add_one(<|>);
280}"#,
281 );
282
283 assert_eq!(desc.name, "add_one".to_string());
284 assert_eq!(desc.params, vec!["x".to_string()]);
285 assert_eq!(desc.ret_type, Some("-> i32".to_string()));
286 assert_eq!(param, Some(0));
287 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string());
288 assert_eq!(
289 desc.doc,
290 Some(
291 r#"Adds one to the number given.
292
293# Examples
294
295```rust
296let five = 5;
297
298assert_eq!(6, my_crate::add_one(5));
299```"#
300 .into()
301 )
302 );
303}
304
305#[test]
306fn test_fn_signature_with_docs_from_actix() {
307 let (desc, param) = get_signature(
308 r#"
309pub trait WriteHandler<E>
310where
311 Self: Actor,
312 Self::Context: ActorContext,
313{
314 /// Method is called when writer emits error.
315 ///
316 /// If this method returns `ErrorAction::Continue` writer processing
317 /// continues otherwise stream processing stops.
318 fn error(&mut self, err: E, ctx: &mut Self::Context) -> Running {
319 Running::Stop
320 }
321
322 /// Method is called when writer finishes.
323 ///
324 /// By default this method stops actor's `Context`.
325 fn finished(&mut self, ctx: &mut Self::Context) {
326 ctx.stop()
327 }
328}
329
330pub fn foo() {
331 WriteHandler r;
332 r.finished(<|>);
333}
334
335"#,
336 );
337
338 assert_eq!(desc.name, "finished".to_string());
339 assert_eq!(
340 desc.params,
341 vec!["&mut self".to_string(), "ctx".to_string()]
342 );
343 assert_eq!(desc.ret_type, None);
344 assert_eq!(param, Some(1));
345 assert_eq!(
346 desc.doc,
347 Some(
348 r#"Method is called when writer finishes.
349
350By default this method stops actor's `Context`."#
351 .into()
352 )
353 );
354}
355
356fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { 97fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> {
357 let (analysis, position) = single_file_with_position(text); 98 let (analysis, position) = single_file_with_position(text);
358 analysis.find_all_refs(position).unwrap() 99 analysis.find_all_refs(position).unwrap()