From a7731be860a10c09784da1e3cd97ff3ce0c5800d Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 3 Nov 2023 02:31:27 +0900 Subject: [PATCH] add tests for multi-bytes characters --- src/history.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++ tests/textarea.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) diff --git a/src/history.rs b/src/history.rs index 540cb5e..e8da053 100644 --- a/src/history.rs +++ b/src/history.rs @@ -525,6 +525,97 @@ mod tests { "", ][..], ), + // Multi-byte characters + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (0, 0), + &[ + "🐷", "🐼", "🐓", + ][..], + &[ + "🐷", + "🐼", + "🐓🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (0, 4 * 2), + &[ + "🐷", "🐼", "🐓", + ][..], + &[ + "🐶🐱🐷", + "🐼", + "🐓", + "🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (1, 0), + &[ + "🐷", "🐼", "🐓", + ][..], + &[ + "🐶🐱", + "🐷", + "🐼", + "🐓🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (1, 4 * 1), + &[ + "🐷", "🐼", "🐓", + ][..], + &[ + "🐶🐱", + "🐮🐷", + "🐼", + "🐓🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (2, 4 * 2), + &[ + "🐷", "🐼", "🐓", + ][..], + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭🐷", + "🐼", + "🐓", + ][..], + ), ]; for (before, pos, input, expected) in tests { diff --git a/tests/textarea.rs b/tests/textarea.rs index 4847b36..6354af4 100644 --- a/tests/textarea.rs +++ b/tests/textarea.rs @@ -375,6 +375,92 @@ fn test_insert_str_multiple_lines() { "", ][..], ), + // Multi-byte characters + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (0, 0), + "🐷\n🐼\n🐓", + (2, 1), + &[ + "🐷", + "🐼", + "🐓🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (0, 2), + "🐷\n🐼\n🐓", + (2, 1), + &[ + "🐶🐱🐷", + "🐼", + "🐓", + "🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (1, 0), + "🐷\n🐼\n🐓", + (3, 1), + &[ + "🐶🐱", + "🐷", + "🐼", + "🐓🐮🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (1, 1), + "🐷\n🐼\n🐓", + (3, 1), + &[ + "🐶🐱", + "🐮🐷", + "🐼", + "🐓🐰", + "🐧🐭", + ][..], + ), + ( + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭", + ][..], + (2, 2), + "🐷\n🐼\n🐓", + (4, 1), + &[ + "🐶🐱", + "🐮🐰", + "🐧🐭🐷", + "🐼", + "🐓", + ][..], + ), ]; for test in tests {