@@ -31,3 +31,35 @@ pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usiz
3131 char_idx + 1
3232 }
3333}
34+
35+#[test]
36+fn different_prev_word_boundary() {
37+ use ropey::Rope;
38+ let t = |x, y| {
39+ let text = Rope::from(x);
40+ let out = nth_prev_word_boundary(text.slice(..), text.len_chars() - 1, 1);
41+ assert_eq!(text.slice(..out), y, r#"from "{}""#, x);
42+ };
43+ t("abcd\nefg\nwrs", "abcd\nefg\n");
44+ t("abcd\nefg\n", "abcd\n");
45+ t("abcd\n", "");
46+ t("hello, world!", "hello, world");
47+ t("hello, world", "hello, ");
48+ t("hello, ", "hello");
49+ t("hello", "");
50+ t("こんにちは、世界!", "こんにちは、世界!"); // TODO: punctuation
51+ t("こんにちは、世界", "こんにちは、");
52+ t("こんにちは、", "こんにちは、"); // what?
53+ t("こんにちは", "");
54+ t("この世界。", "この世界。"); // what?
55+ t("この世界", "");
56+ t("お前はもう死んでいる", "");
57+ t("その300円です", ""); // TODO: should stop at 300
58+ t("唱k", ""); // TODO: should stop at 唱
59+ t("1 + 1 = 2", "1 + 1 = ");
60+ t("1 + 1 =", "1 + 1 ");
61+ t("1 + 1", "1 + ");
62+ t("1 + ", "1 ");
63+ t("1 ", "");
64+ t("1+1=2", "1+1=");
65+}