From 07a9a7463f2fdac74185aaa678fec9b7571a80ae Mon Sep 17 00:00:00 2001 From: sholderbach Date: Sat, 24 Sep 2022 17:24:34 +0200 Subject: [PATCH] Add tests for `cut_right_until_char` (#484) I discovered a limitation in how we handle character searches with a multiplier in the case the search character appears in a consecutive sequence. Fixing this correctly probably requires performing the search with knowledge of the multiplier. --- src/core_editor/editor.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/core_editor/editor.rs b/src/core_editor/editor.rs index bd4aded..66ab7b0 100644 --- a/src/core_editor/editor.rs +++ b/src/core_editor/editor.rs @@ -505,6 +505,32 @@ mod test { assert_eq!(editor.get_buffer(), expected); } + #[rstest] + #[case("hello world", 0, 'l', 1, false, "lo world")] + #[case("hello world", 0, 'l', 1, true, "llo world")] + #[ignore = "Deleting two consecutives is not implemented correctly and needs the multiplier explicitly."] + #[case("hello world", 0, 'l', 2, false, "o world")] + #[case("hello world", 0, 'h', 1, false, "hello world")] + #[case("hello world", 0, 'l', 3, true, "ld")] + #[case("hello world", 4, 'o', 1, true, "hellorld")] + #[case("hello world", 4, 'w', 1, false, "hellorld")] + #[case("hello world", 4, 'o', 1, false, "hellrld")] + fn test_cut_right_until_char( + #[case] input: &str, + #[case] position: usize, + #[case] search_char: char, + #[case] repeat: usize, + #[case] before_char: bool, + #[case] expected: &str, + ) { + let mut editor = editor_with(input); + editor.line_buffer.set_insertion_point(position); + for _ in 0..repeat { + editor.cut_right_until_char(search_char, before_char, true); + } + assert_eq!(editor.get_buffer(), expected); + } + #[rstest] #[case("abc", 1, 'X', "aXc")] #[case("abc", 1, '🔄', "a🔄c")]