diff options
Diffstat (limited to 'crates/libeditor/src/extend_selection.rs')
-rw-r--r-- | crates/libeditor/src/extend_selection.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs index 154f89671..30cff6558 100644 --- a/crates/libeditor/src/extend_selection.rs +++ b/crates/libeditor/src/extend_selection.rs | |||
@@ -64,3 +64,58 @@ fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { | |||
64 | } | 64 | } |
65 | res | 65 | res |
66 | } | 66 | } |
67 | |||
68 | #[cfg(test)] | ||
69 | mod tests { | ||
70 | use super::*; | ||
71 | use test_utils::extract_offset; | ||
72 | |||
73 | fn do_check(before: &str, afters: &[&str]) { | ||
74 | let (cursor, before) = extract_offset(before); | ||
75 | let file = File::parse(&before); | ||
76 | let mut range = TextRange::offset_len(cursor, 0.into()); | ||
77 | for &after in afters { | ||
78 | range = extend_selection(&file, range) | ||
79 | .unwrap(); | ||
80 | let actual = &before[range]; | ||
81 | assert_eq!(after, actual); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | #[test] | ||
86 | fn test_extend_selection_arith() { | ||
87 | do_check( | ||
88 | r#"fn foo() { <|>1 + 1 }"#, | ||
89 | &["1", "1 + 1", "{ 1 + 1 }"], | ||
90 | ); | ||
91 | } | ||
92 | |||
93 | #[test] | ||
94 | fn test_extend_selection_start_of_the_lind() { | ||
95 | do_check( | ||
96 | r#" | ||
97 | impl S { | ||
98 | <|> fn foo() { | ||
99 | |||
100 | } | ||
101 | }"#, | ||
102 | &["fn foo() {\n\n }"] | ||
103 | ); | ||
104 | } | ||
105 | |||
106 | #[test] | ||
107 | fn test_extend_selection_comments() { | ||
108 | do_check( | ||
109 | r#" | ||
110 | fn bar(){} | ||
111 | |||
112 | // fn foo() { | ||
113 | // 1 + <|>1 | ||
114 | // } | ||
115 | |||
116 | // fn foo(){} | ||
117 | "#, | ||
118 | &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"] | ||
119 | ); | ||
120 | } | ||
121 | } | ||