aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/tests')
-rw-r--r--crates/libeditor/tests/test.rs49
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]
182fn 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"
192fn foo() {
193 <|>foo(1,
194 )
195}
196", r"
197fn foo() {
198 <|>foo(1, )
199}
200");
201}
202
203#[test]
204fn 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"
216fn foo() {
217 <|>foo(1,
218 2,
219 3,
220 <|>)
221}
222", r"
223fn foo() {
224 foo(1, 2, 3, )
225}
226");
227}
228
180fn file(text: &str) -> ParsedFile { 229fn file(text: &str) -> ParsedFile {
181 ParsedFile::parse(text) 230 ParsedFile::parse(text)
182} 231}