From 6dcf87fb5f17393028a031b00a562ea8b74267ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 23 Aug 2018 20:55:23 +0300 Subject: Start join-lines --- crates/libeditor/tests/test.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'crates/libeditor/tests/test.rs') 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::{ ParsedFile, TextUnit, TextRange, ActionResult, highlight, runnables, extend_selection, file_structure, flip_comma, add_derive, add_impl, matching_brace, + join_lines, }; #[test] @@ -177,6 +178,54 @@ fn test_matching_brace() { ); } +#[test] +fn test_join_lines_cursor() { + fn do_check(before: &str, after: &str) { + check_action(before, after, |file, offset| { + let range = TextRange::offset_len(offset, 0.into()); + let res = join_lines(file, range); + Some(res) + }) + } + + do_check(r" +fn foo() { + <|>foo(1, + ) +} +", r" +fn foo() { + <|>foo(1, ) +} +"); +} + +#[test] +fn test_join_lines_selection() { + fn do_check(before: &str, after: &str) { + let (sel_start, before) = extract_cursor(before); + let (sel_end, before) = extract_cursor(&before); + let sel = TextRange::from_to(sel_start, sel_end); + let file = file(&before); + let result = join_lines(&file, sel); + let actual = result.edit.apply(&before); + assert_eq_text!(after, &actual); + } + + do_check(r" +fn foo() { + <|>foo(1, + 2, + 3, + <|>) +} +", r" +fn foo() { + foo(1, 2, 3, ) +} +"); +} + fn file(text: &str) -> ParsedFile { ParsedFile::parse(text) } -- cgit v1.2.3