diff options
author | Aleksey Kladov <[email protected]> | 2019-01-11 15:17:20 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-11 15:32:22 +0000 |
commit | dda916bc4d51383fcf84f736bd12c7a77c445fb0 (patch) | |
tree | 1d1a8246105eba1a16fd066365ea095ff0377740 /crates/ra_ide_api/src/goto_definition.rs | |
parent | 8a5f74a24f726a839f3a0e154cfadec23040e14c (diff) |
fix tests
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 3fb29950b..8d2ff561a 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -85,31 +85,32 @@ fn name_definition( | |||
85 | 85 | ||
86 | #[cfg(test)] | 86 | #[cfg(test)] |
87 | mod tests { | 87 | mod tests { |
88 | use test_utils::assert_eq_dbg; | ||
89 | use crate::mock_analysis::analysis_and_position; | 88 | use crate::mock_analysis::analysis_and_position; |
90 | 89 | ||
90 | fn check_goto(fixuture: &str, expected: &str) { | ||
91 | let (analysis, pos) = analysis_and_position(fixuture); | ||
92 | |||
93 | let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info; | ||
94 | assert_eq!(navs.len(), 1); | ||
95 | let nav = navs.pop().unwrap(); | ||
96 | nav.assert_match(expected); | ||
97 | } | ||
98 | |||
91 | #[test] | 99 | #[test] |
92 | fn goto_definition_works_in_items() { | 100 | fn goto_definition_works_in_items() { |
93 | let (analysis, pos) = analysis_and_position( | 101 | check_goto( |
94 | " | 102 | " |
95 | //- /lib.rs | 103 | //- /lib.rs |
96 | struct Foo; | 104 | struct Foo; |
97 | enum E { X(Foo<|>) } | 105 | enum E { X(Foo<|>) } |
98 | ", | 106 | ", |
99 | ); | 107 | "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", |
100 | |||
101 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); | ||
102 | assert_eq_dbg( | ||
103 | r#"[NavigationTarget { file_id: FileId(1), name: "Foo", | ||
104 | kind: STRUCT_DEF, range: [0; 11), | ||
105 | ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, | ||
106 | &symbols, | ||
107 | ); | 108 | ); |
108 | } | 109 | } |
109 | 110 | ||
110 | #[test] | 111 | #[test] |
111 | fn goto_definition_resolves_correct_name() { | 112 | fn goto_definition_resolves_correct_name() { |
112 | let (analysis, pos) = analysis_and_position( | 113 | check_goto( |
113 | " | 114 | " |
114 | //- /lib.rs | 115 | //- /lib.rs |
115 | use a::Foo; | 116 | use a::Foo; |
@@ -121,47 +122,30 @@ mod tests { | |||
121 | //- /b.rs | 122 | //- /b.rs |
122 | struct Foo; | 123 | struct Foo; |
123 | ", | 124 | ", |
124 | ); | 125 | "Foo STRUCT_DEF FileId(2) [0; 11) [7; 10)", |
125 | |||
126 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); | ||
127 | assert_eq_dbg( | ||
128 | r#"[NavigationTarget { file_id: FileId(2), name: "Foo", | ||
129 | kind: STRUCT_DEF, range: [0; 11), | ||
130 | ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, | ||
131 | &symbols, | ||
132 | ); | 126 | ); |
133 | } | 127 | } |
134 | 128 | ||
135 | #[test] | 129 | #[test] |
136 | fn goto_definition_works_for_module_declaration() { | 130 | fn goto_definition_works_for_module_declaration() { |
137 | let (analysis, pos) = analysis_and_position( | 131 | check_goto( |
138 | " | 132 | " |
139 | //- /lib.rs | 133 | //- /lib.rs |
140 | mod <|>foo; | 134 | mod <|>foo; |
141 | //- /foo.rs | 135 | //- /foo.rs |
142 | // empty | 136 | // empty |
143 | ", | 137 | ", |
144 | ); | 138 | "foo SOURCE_FILE FileId(2) [0; 10)", |
145 | |||
146 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); | ||
147 | assert_eq_dbg( | ||
148 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | ||
149 | &symbols, | ||
150 | ); | 139 | ); |
151 | 140 | ||
152 | let (analysis, pos) = analysis_and_position( | 141 | check_goto( |
153 | " | 142 | " |
154 | //- /lib.rs | 143 | //- /lib.rs |
155 | mod <|>foo; | 144 | mod <|>foo; |
156 | //- /foo/mod.rs | 145 | //- /foo/mod.rs |
157 | // empty | 146 | // empty |
158 | ", | 147 | ", |
159 | ); | 148 | "foo SOURCE_FILE FileId(2) [0; 10)", |
160 | |||
161 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); | ||
162 | assert_eq_dbg( | ||
163 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | ||
164 | &symbols, | ||
165 | ); | 149 | ); |
166 | } | 150 | } |
167 | } | 151 | } |