diff options
author | Aleksey Kladov <[email protected]> | 2018-08-23 18:55:23 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-23 18:55:23 +0100 |
commit | 6dcf87fb5f17393028a031b00a562ea8b74267ca (patch) | |
tree | 05de66dc2944ca78e34b507f80e7e12056d4f867 /crates/libeditor/tests | |
parent | ec706175645172ee4bd5d3d4c0645ffb45d79bbf (diff) |
Start join-lines
Diffstat (limited to 'crates/libeditor/tests')
-rw-r--r-- | crates/libeditor/tests/test.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index 42926ffc8..6aa260a86 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs | |||
@@ -8,6 +8,7 @@ use libeditor::{ | |||
8 | ParsedFile, TextUnit, TextRange, ActionResult, | 8 | ParsedFile, TextUnit, TextRange, ActionResult, |
9 | highlight, runnables, extend_selection, file_structure, | 9 | highlight, runnables, extend_selection, file_structure, |
10 | flip_comma, add_derive, add_impl, matching_brace, | 10 | flip_comma, add_derive, add_impl, matching_brace, |
11 | join_lines, | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | #[test] | 14 | #[test] |
@@ -177,6 +178,54 @@ fn test_matching_brace() { | |||
177 | ); | 178 | ); |
178 | } | 179 | } |
179 | 180 | ||
181 | #[test] | ||
182 | fn test_join_lines_cursor() { | ||
183 | fn do_check(before: &str, after: &str) { | ||
184 | check_action(before, after, |file, offset| { | ||
185 | let range = TextRange::offset_len(offset, 0.into()); | ||
186 | let res = join_lines(file, range); | ||
187 | Some(res) | ||
188 | }) | ||
189 | } | ||
190 | |||
191 | do_check(r" | ||
192 | fn foo() { | ||
193 | <|>foo(1, | ||
194 | ) | ||
195 | } | ||
196 | ", r" | ||
197 | fn foo() { | ||
198 | <|>foo(1, ) | ||
199 | } | ||
200 | "); | ||
201 | } | ||
202 | |||
203 | #[test] | ||
204 | fn test_join_lines_selection() { | ||
205 | fn do_check(before: &str, after: &str) { | ||
206 | let (sel_start, before) = extract_cursor(before); | ||
207 | let (sel_end, before) = extract_cursor(&before); | ||
208 | let sel = TextRange::from_to(sel_start, sel_end); | ||
209 | let file = file(&before); | ||
210 | let result = join_lines(&file, sel); | ||
211 | let actual = result.edit.apply(&before); | ||
212 | assert_eq_text!(after, &actual); | ||
213 | } | ||
214 | |||
215 | do_check(r" | ||
216 | fn foo() { | ||
217 | <|>foo(1, | ||
218 | 2, | ||
219 | 3, | ||
220 | <|>) | ||
221 | } | ||
222 | ", r" | ||
223 | fn foo() { | ||
224 | foo(1, 2, 3, ) | ||
225 | } | ||
226 | "); | ||
227 | } | ||
228 | |||
180 | fn file(text: &str) -> ParsedFile { | 229 | fn file(text: &str) -> ParsedFile { |
181 | ParsedFile::parse(text) | 230 | ParsedFile::parse(text) |
182 | } | 231 | } |