add tests

This commit is contained in:
Dongdong Zhou 2022-10-15 21:40:40 +01:00
parent 59b9a9d1d9
commit 43d6e46660
2 changed files with 16 additions and 3 deletions

View File

@ -10,6 +10,7 @@
- [#1475](https://github.com/lapce/lapce/pull/1475): Add editor setting: "Cursor Surrounding Lines" which sets minimum number of lines above and below cursor
- [#1525](https://github.com/lapce/lapce/pull/1525): Add editor indent guide
- [#1521](https://github.com/lapce/lapce/pull/1521): Show unique paths to disambiguate same file names
- [#1452](https://github.com/lapce/lapce/pull/1452): Wrap selected text with brackets/quotes
### Bug Fixes

View File

@ -93,9 +93,10 @@ pub fn insert(
// when text is selected, and [,{,(,'," is inserted
// wrap the text with that char and its corresponding closing pair
if region.start != region.end && matching_pair_type == Some(true)
|| c == '"'
|| c == '\''
if region.start != region.end
&& (matching_pair_type == Some(true)
|| c == '"'
|| c == '\'')
{
edits.push((
Selection::region(region.min(), region.min()),
@ -1494,6 +1495,17 @@ fn test_insert_pair() {
assert_eq!("a{} bc\ne{} fg\n", buffer.slice_to_cow(0..buffer.len()));
}
#[test]
fn test_insert_pair_with_selection() {
let mut buffer = Buffer::new("a bc\ne fg\n");
let mut selection = Selection::new();
selection.add_region(SelRegion::new(0, 4, None));
selection.add_region(SelRegion::new(5, 9, None));
let mut cursor = Cursor::new(CursorMode::Insert(selection), None, None);
Editor::insert(&mut cursor, &mut buffer, "{", None, true);
assert_eq!("{a bc}\n{e fg}\n", buffer.slice_to_cow(0..buffer.len()));
}
#[test]
fn test_insert_pair_without_auto_closing() {
let mut buffer = Buffer::new("a bc\ne fg\n");