diff options
author | Aleksey Kladov <[email protected]> | 2019-01-05 16:41:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-05 16:41:43 +0000 |
commit | da32463cbf8dc32229eb13844c71a40df2d3b77e (patch) | |
tree | b64b08018711ef6021a1ad00c4246d10cfdc44e0 | |
parent | c2a0f5e50f6deb2e15bbfa6056a3cc0866c203a5 (diff) |
inline goto_defention tests
-rw-r--r-- | crates/ra_analysis/src/goto_defenition.rs | 58 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_analysis/tests/test/main.rs | 59 |
3 files changed, 58 insertions, 66 deletions
diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs index 91de7ef65..08d1809ee 100644 --- a/crates/ra_analysis/src/goto_defenition.rs +++ b/crates/ra_analysis/src/goto_defenition.rs | |||
@@ -78,3 +78,61 @@ fn name_defenition( | |||
78 | } | 78 | } |
79 | Ok(None) | 79 | Ok(None) |
80 | } | 80 | } |
81 | |||
82 | #[cfg(test)] | ||
83 | mod tests { | ||
84 | use test_utils::assert_eq_dbg; | ||
85 | use crate::mock_analysis::analysis_and_position; | ||
86 | |||
87 | #[test] | ||
88 | fn goto_defenition_works_in_items() { | ||
89 | let (analysis, pos) = analysis_and_position( | ||
90 | " | ||
91 | //- /lib.rs | ||
92 | struct Foo; | ||
93 | enum E { X(Foo<|>) } | ||
94 | ", | ||
95 | ); | ||
96 | |||
97 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | ||
98 | assert_eq_dbg( | ||
99 | r#"[NavigationTarget { file_id: FileId(1), name: "Foo", | ||
100 | kind: STRUCT_DEF, range: [0; 11), | ||
101 | ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, | ||
102 | &symbols, | ||
103 | ); | ||
104 | } | ||
105 | |||
106 | #[test] | ||
107 | fn goto_defenition_works_for_module_declaration() { | ||
108 | let (analysis, pos) = analysis_and_position( | ||
109 | " | ||
110 | //- /lib.rs | ||
111 | mod <|>foo; | ||
112 | //- /foo.rs | ||
113 | // empty | ||
114 | ", | ||
115 | ); | ||
116 | |||
117 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | ||
118 | assert_eq_dbg( | ||
119 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | ||
120 | &symbols, | ||
121 | ); | ||
122 | |||
123 | let (analysis, pos) = analysis_and_position( | ||
124 | " | ||
125 | //- /lib.rs | ||
126 | mod <|>foo; | ||
127 | //- /foo/mod.rs | ||
128 | // empty | ||
129 | ", | ||
130 | ); | ||
131 | |||
132 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | ||
133 | assert_eq_dbg( | ||
134 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | ||
135 | &symbols, | ||
136 | ); | ||
137 | } | ||
138 | } | ||
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 0dac9f268..13527e628 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -399,13 +399,6 @@ impl Analysis { | |||
399 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 399 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { |
400 | goto_defenition::goto_defenition(&*self.db, position) | 400 | goto_defenition::goto_defenition(&*self.db, position) |
401 | } | 401 | } |
402 | // /// Resolves reference to definition, but does not gurantee correctness. | ||
403 | // pub fn approximately_resolve_symbol( | ||
404 | // &self, | ||
405 | // position: FilePosition, | ||
406 | // ) -> Cancelable<Option<ReferenceResolution>> { | ||
407 | // self.db.approximately_resolve_symbol(position) | ||
408 | // } | ||
409 | /// Finds all usages of the reference at point. | 402 | /// Finds all usages of the reference at point. |
410 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 403 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
411 | self.db.find_all_refs(position) | 404 | self.db.find_all_refs(position) |
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs index beeae1e19..e15035304 100644 --- a/crates/ra_analysis/tests/test/main.rs +++ b/crates/ra_analysis/tests/test/main.rs | |||
@@ -15,65 +15,6 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | #[test] | 17 | #[test] |
18 | fn approximate_resolve_works_in_items() { | ||
19 | let (analysis, pos) = analysis_and_position( | ||
20 | " | ||
21 | //- /lib.rs | ||
22 | struct Foo; | ||
23 | enum E { X(Foo<|>) } | ||
24 | ", | ||
25 | ); | ||
26 | |||
27 | let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); | ||
28 | assert_eq_dbg( | ||
29 | r#"ReferenceResolution { | ||
30 | reference_range: [23; 26), | ||
31 | resolves_to: [NavigationTarget { file_id: FileId(1), name: "Foo", kind: STRUCT_DEF, range: [0; 11), ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }] | ||
32 | }"#, | ||
33 | &symbols, | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | #[test] | ||
38 | fn test_resolve_module() { | ||
39 | let (analysis, pos) = analysis_and_position( | ||
40 | " | ||
41 | //- /lib.rs | ||
42 | mod <|>foo; | ||
43 | //- /foo.rs | ||
44 | // empty | ||
45 | ", | ||
46 | ); | ||
47 | |||
48 | let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); | ||
49 | assert_eq_dbg( | ||
50 | r#"ReferenceResolution { | ||
51 | reference_range: [4; 7), | ||
52 | resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }] | ||
53 | }"#, | ||
54 | &symbols, | ||
55 | ); | ||
56 | |||
57 | let (analysis, pos) = analysis_and_position( | ||
58 | " | ||
59 | //- /lib.rs | ||
60 | mod <|>foo; | ||
61 | //- /foo/mod.rs | ||
62 | // empty | ||
63 | ", | ||
64 | ); | ||
65 | |||
66 | let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); | ||
67 | assert_eq_dbg( | ||
68 | r#"ReferenceResolution { | ||
69 | reference_range: [4; 7), | ||
70 | resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }] | ||
71 | }"#, | ||
72 | &symbols, | ||
73 | ); | ||
74 | } | ||
75 | |||
76 | #[test] | ||
77 | fn test_unresolved_module_diagnostic() { | 18 | fn test_unresolved_module_diagnostic() { |
78 | let (analysis, file_id) = single_file("mod foo;"); | 19 | let (analysis, file_id) = single_file("mod foo;"); |
79 | let diagnostics = analysis.diagnostics(file_id).unwrap(); | 20 | let diagnostics = analysis.diagnostics(file_id).unwrap(); |