diff options
Diffstat (limited to 'crates/libeditor/tests')
-rw-r--r-- | crates/libeditor/tests/test.rs | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index a2e26003a..f8365949e 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs | |||
@@ -12,15 +12,32 @@ use libeditor::{ | |||
12 | 12 | ||
13 | #[test] | 13 | #[test] |
14 | fn test_extend_selection() { | 14 | fn test_extend_selection() { |
15 | let file = file(r#"fn foo() { | 15 | fn do_check(before: &str, afters: &[&str]) { |
16 | 1 + 1 | 16 | let (cursor, before) = extract_cursor(before); |
17 | } | 17 | let file = file(&before); |
18 | "#); | 18 | let mut range = TextRange::offset_len(cursor, 0.into()); |
19 | let range = TextRange::offset_len(18.into(), 0.into()); | 19 | for &after in afters { |
20 | let range = extend_selection(&file, range).unwrap(); | 20 | range = extend_selection(&file, range) |
21 | assert_eq!(range, TextRange::from_to(17.into(), 18.into())); | 21 | .unwrap(); |
22 | let range = extend_selection(&file, range).unwrap(); | 22 | let actual = &before[range]; |
23 | assert_eq!(range, TextRange::from_to(15.into(), 20.into())); | 23 | assert_eq!(after, actual); |
24 | } | ||
25 | } | ||
26 | |||
27 | do_check( | ||
28 | r#"fn foo() { <|>1 + 1 }"#, | ||
29 | &["1", "1 + 1", "{ 1 + 1 }"], | ||
30 | ); | ||
31 | |||
32 | do_check( | ||
33 | r#" | ||
34 | impl S { | ||
35 | <|> fn foo() { | ||
36 | |||
37 | } | ||
38 | }"#, | ||
39 | &["fn foo() {\n\n }"] | ||
40 | ); | ||
24 | } | 41 | } |
25 | 42 | ||
26 | #[test] | 43 | #[test] |