aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/typing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/typing.rs')
-rw-r--r--crates/libeditor/src/typing.rs129
1 files changed, 129 insertions, 0 deletions
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs
index daa57983f..952caf7f6 100644
--- a/crates/libeditor/src/typing.rs
+++ b/crates/libeditor/src/typing.rs
@@ -163,3 +163,132 @@ fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str {
163 } 163 }
164 " " 164 " "
165} 165}
166
167#[cfg(test)]
168mod tests {
169 use super::*;
170 use test_utils::{check_action, extract_range, extract_offset};
171
172 fn check_join_lines(before: &str, after: &str) {
173 check_action(before, after, |file, offset| {
174 let range = TextRange::offset_len(offset, 0.into());
175 let res = join_lines(file, range);
176 Some(res)
177 })
178 }
179
180 #[test]
181 fn test_join_lines_comma() {
182 check_join_lines(r"
183fn foo() {
184 <|>foo(1,
185 )
186}
187", r"
188fn foo() {
189 <|>foo(1)
190}
191");
192 }
193
194 #[test]
195 fn test_join_lines_lambda_block() {
196 check_join_lines(r"
197pub fn reparse(&self, edit: &AtomEdit) -> File {
198 <|>self.incremental_reparse(edit).unwrap_or_else(|| {
199 self.full_reparse(edit)
200 })
201}
202", r"
203pub fn reparse(&self, edit: &AtomEdit) -> File {
204 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
205}
206");
207 }
208
209 #[test]
210 fn test_join_lines_block() {
211 check_join_lines(r"
212fn foo() {
213 foo(<|>{
214 92
215 })
216}", r"
217fn foo() {
218 foo(<|>92)
219}");
220 }
221
222 #[test]
223 fn test_join_lines_selection() {
224 fn do_check(before: &str, after: &str) {
225 let (sel, before) = extract_range(before);
226 let file = File::parse(&before);
227 let result = join_lines(&file, sel);
228 let actual = result.edit.apply(&before);
229 assert_eq_text!(after, &actual);
230 }
231
232 do_check(r"
233fn foo() {
234 <|>foo(1,
235 2,
236 3,
237 <|>)
238}
239 ", r"
240fn foo() {
241 foo(1, 2, 3)
242}
243 ");
244
245 do_check(r"
246struct Foo <|>{
247 f: u32,
248}<|>
249 ", r"
250struct Foo { f: u32 }
251 ");
252 }
253
254 #[test]
255 fn test_on_eq_typed() {
256 fn do_check(before: &str, after: &str) {
257 let (offset, before) = extract_offset(before);
258 let file = File::parse(&before);
259 let result = on_eq_typed(&file, offset).unwrap();
260 let actual = result.edit.apply(&before);
261 assert_eq_text!(after, &actual);
262 }
263
264 // do_check(r"
265 // fn foo() {
266 // let foo =<|>
267 // }
268 // ", r"
269 // fn foo() {
270 // let foo =;
271 // }
272 // ");
273 do_check(r"
274fn foo() {
275 let foo =<|> 1 + 1
276}
277", r"
278fn foo() {
279 let foo = 1 + 1;
280}
281");
282 // do_check(r"
283 // fn foo() {
284 // let foo =<|>
285 // let bar = 1;
286 // }
287 // ", r"
288 // fn foo() {
289 // let foo =;
290 // let bar = 1;
291 // }
292 // ");
293 }
294}