aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorIvan Tham2021-06-06 11:25:16 +0000
committerBlaž Hrastnik2021-06-06 12:30:18 +0000
commitdf80f3c966ae92f8e00e8aee19d0e1b65f2b5669 (patch)
tree55e824d4c59646bde5d8563e78674d08881fb382 /helix-core/src
parent40744ce8356cb9307f8cb9b2adf2c57b80b1ef9f (diff)
Add test for prev word
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/words.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/helix-core/src/words.rs b/helix-core/src/words.rs
index 0099d56a..5ff25050 100644
--- a/helix-core/src/words.rs
+++ b/helix-core/src/words.rs
@@ -31,3 +31,35 @@ pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usiz
char_idx + 1
}
}
+
+#[test]
+fn different_prev_word_boundary() {
+ use ropey::Rope;
+ let t = |x, y| {
+ let text = Rope::from(x);
+ let out = nth_prev_word_boundary(text.slice(..), text.len_chars() - 1, 1);
+ assert_eq!(text.slice(..out), y, r#"from "{}""#, x);
+ };
+ t("abcd\nefg\nwrs", "abcd\nefg\n");
+ t("abcd\nefg\n", "abcd\n");
+ t("abcd\n", "");
+ t("hello, world!", "hello, world");
+ t("hello, world", "hello, ");
+ t("hello, ", "hello");
+ t("hello", "");
+ t("こんにちは、世界!", "こんにちは、世界!"); // TODO: punctuation
+ t("こんにちは、世界", "こんにちは、");
+ t("こんにちは、", "こんにちは、"); // what?
+ t("こんにちは", "");
+ t("この世界。", "この世界。"); // what?
+ t("この世界", "");
+ t("お前はもう死んでいる", "");
+ t("その300円です", ""); // TODO: should stop at 300
+ t("唱k", ""); // TODO: should stop at 唱
+ t("1 + 1 = 2", "1 + 1 = ");
+ t("1 + 1 =", "1 + 1 ");
+ t("1 + 1", "1 + ");
+ t("1 + ", "1 ");
+ t("1 ", "");
+ t("1+1=2", "1+1=");
+}