From 641659d5a8dcca0b8a1c36ff6d1c517a91296116 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Aug 2018 11:56:36 +0300 Subject: Smarter extend selection --- crates/libeditor/tests/test.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'crates/libeditor/tests') 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::{ #[test] fn test_extend_selection() { - let file = file(r#"fn foo() { - 1 + 1 -} -"#); - let range = TextRange::offset_len(18.into(), 0.into()); - let range = extend_selection(&file, range).unwrap(); - assert_eq!(range, TextRange::from_to(17.into(), 18.into())); - let range = extend_selection(&file, range).unwrap(); - assert_eq!(range, TextRange::from_to(15.into(), 20.into())); + fn do_check(before: &str, afters: &[&str]) { + let (cursor, before) = extract_cursor(before); + let file = file(&before); + let mut range = TextRange::offset_len(cursor, 0.into()); + for &after in afters { + range = extend_selection(&file, range) + .unwrap(); + let actual = &before[range]; + assert_eq!(after, actual); + } + } + + do_check( + r#"fn foo() { <|>1 + 1 }"#, + &["1", "1 + 1", "{ 1 + 1 }"], + ); + + do_check( + r#" +impl S { +<|> fn foo() { + + } +}"#, + &["fn foo() {\n\n }"] + ); } #[test] -- cgit v1.2.3