@@ -589,6 +589,90 @@ mod test {
593+ fn test_behaviour_when_moving_to_start_of_next_long_words() {
594+ let tests = array::IntoIter::new([
595+ ("Basic forward motion stops at the first space",
596+ vec![(1, Range::new(0, 0), Range::new(0, 5))]),
597+ (" Starting from a boundary advances the anchor",
598+ vec![(1, Range::new(0, 0), Range::new(1, 9))]),
599+ ("Long whitespace gap is bridged by the head",
600+ vec![(1, Range::new(0, 0), Range::new(0, 10))]),
601+ ("Previous anchor is irrelevant for forward motions",
602+ vec![(1, Range::new(12, 0), Range::new(0, 8))]),
603+ (" Starting from whitespace moves to last space in sequence",
604+ vec![(1, Range::new(0, 0), Range::new(0, 3))]),
605+ ("Starting from mid-word leaves anchor at start position and moves head",
606+ vec![(1, Range::new(3, 3), Range::new(3, 8))]),
607+ ("Identifiers_with_underscores are considered a single word",
608+ vec![(1, Range::new(0, 0), Range::new(0, 28))]),
609+ ("Jumping\n into starting whitespace selects the spaces before 'into'",
610+ vec![(1, Range::new(0, 6), Range::new(8, 11))]),
611+ ("alphanumeric.!,and.?=punctuation are not treated any differently than alphanumerics",
613+ (1, Range::new(0, 0), Range::new(0, 32)),
615+ ("... ... punctuation and spaces behave as expected",
617+ (1, Range::new(0, 0), Range::new(0, 5)),
618+ (1, Range::new(0, 5), Range::new(6, 9)),
620+ (".._.._ punctuation is joined by underscores into a single word, as it behaves like alphanumerics",
621+ vec![(1, Range::new(0, 0), Range::new(0, 6))]),
622+ ("Newlines\n\nare bridged seamlessly.",
624+ (1, Range::new(0, 0), Range::new(0, 7)),
625+ (1, Range::new(0, 7), Range::new(10, 13)),
627+ ("Jumping\n\n\n\n\n\n from newlines to whitespace selects whitespace.",
629+ (1, Range::new(0, 8), Range::new(13, 15)),
631+ ("A failed motion does not modify the range",
633+ (3, Range::new(37, 41), Range::new(37, 41)),
635+ ("oh oh oh two character words!",
637+ (1, Range::new(0, 0), Range::new(0, 2)),
638+ (1, Range::new(0, 2), Range::new(3, 5)),
639+ (1, Range::new(0, 1), Range::new(2, 2)),
641+ ("Multiple motions at once resolve correctly",
643+ (3, Range::new(0, 0), Range::new(17, 19)),
645+ ("Excessive motions are performed partially",
647+ (999, Range::new(0, 0), Range::new(32, 40)),
649+ ("", // Edge case of moving forward in empty string
651+ (1, Range::new(0, 0), Range::new(0, 0)),
653+ ("\n\n\n\n\n", // Edge case of moving forward in all newlines
655+ (1, Range::new(0, 0), Range::new(0, 4)),
657+ ("\n \n \n Jumping through alternated space blocks and newlines selects the space blocks",
659+ (1, Range::new(0, 0), Range::new(1, 3)),
660+ (1, Range::new(1, 3), Range::new(5, 7)),
662+ ("ヒー..リクス multibyte characters behave as normal characters, including their interaction with punctuation",
664+ (1, Range::new(0, 0), Range::new(0, 7)),
668+ for (sample, scenario) in tests {
669+ for (count, begin, expected_end) in scenario.into_iter() {
670+ let range = move_next_long_word_start(Rope::from(sample).slice(..), begin, count);
671+ assert_eq!(range, expected_end, "Case failed: [{}]", sample);
593 fn test_behaviour_when_moving_to_start_of_previous_words() {
677 fn test_behaviour_when_moving_to_start_of_previous_words() {
594 let tests = array::IntoIter::new([
678 let tests = array::IntoIter::new([
@@ -671,6 +755,86 @@ mod test {
759+ fn test_behaviour_when_moving_to_start_of_previous_long_words() {
760+ let tests = array::IntoIter::new([
761+ ("Basic backward motion from the middle of a word",
762+ vec![(1, Range::new(3, 3), Range::new(3, 0))]),
763+ ("Starting from after boundary retreats the anchor",
764+ vec![(1, Range::new(0, 8), Range::new(7, 0))]),
765+ (" Jump to start of a word preceded by whitespace",
766+ vec![(1, Range::new(5, 5), Range::new(5, 4))]),
767+ (" Jump to start of line from start of word preceded by whitespace",
768+ vec![(1, Range::new(4, 4), Range::new(3, 0))]),
769+ ("Previous anchor is irrelevant for backward motions",
770+ vec![(1, Range::new(12, 5), Range::new(5, 0))]),
771+ (" Starting from whitespace moves to first space in sequence",
772+ vec![(1, Range::new(0, 3), Range::new(3, 0))]),
773+ ("Identifiers_with_underscores are considered a single word",
774+ vec![(1, Range::new(0, 20), Range::new(20, 0))]),
775+ ("Jumping\n \nback through a newline selects whitespace",
776+ vec![(1, Range::new(0, 13), Range::new(11, 8))]),
777+ ("Jumping to start of word from the end selects the word",
778+ vec![(1, Range::new(6, 6), Range::new(6, 0))]),
779+ ("alphanumeric.!,and.?=punctuation are treated exactly the same",
781+ (1, Range::new(30, 30), Range::new(30, 0)),
784+ ("... ... punctuation and spaces behave as expected",
786+ (1, Range::new(0, 10), Range::new(9, 6)),
787+ (1, Range::new(9, 6), Range::new(5, 0)),
789+ (".._.._ punctuation is joined by underscores into a single block",
790+ vec![(1, Range::new(0, 5), Range::new(4, 0))]),
791+ ("Newlines\n\nare bridged seamlessly.",
793+ (1, Range::new(0, 10), Range::new(7, 0)),
795+ ("Jumping \n\n\n\n\nback from within a newline group selects previous block",
797+ (1, Range::new(0, 13), Range::new(10, 0)),
799+ ("Failed motions do not modify the range",
801+ (0, Range::new(3, 0), Range::new(3, 0)),
803+ ("Multiple motions at once resolve correctly",
805+ (3, Range::new(18, 18), Range::new(8, 0)),
807+ ("Excessive motions are performed partially",
809+ (999, Range::new(40, 40), Range::new(9, 0)),
811+ ("", // Edge case of moving backwards in empty string
813+ (1, Range::new(0, 0), Range::new(0, 0)),
815+ ("\n\n\n\n\n", // Edge case of moving backwards in all newlines
817+ (1, Range::new(0, 0), Range::new(0, 0)),
819+ (" \n \nJumping back through alternated space blocks and newlines selects the space blocks",
821+ (1, Range::new(0, 7), Range::new(6, 4)),
822+ (1, Range::new(6, 4), Range::new(2, 0)),
824+ ("ヒーリ..クス multibyte characters behave as normal characters, including when interacting with punctuation",
826+ (1, Range::new(0, 7), Range::new(6, 0)),
830+ for (sample, scenario) in tests {
831+ for (count, begin, expected_end) in scenario.into_iter() {
832+ let range = move_prev_long_word_start(Rope::from(sample).slice(..), begin, count);
833+ assert_eq!(range, expected_end, "Case failed: [{}]", sample);
675 fn test_behaviour_when_moving_to_end_of_next_words() {
839 fn test_behaviour_when_moving_to_end_of_next_words() {
676 let tests = array::IntoIter::new([
840 let tests = array::IntoIter::new([
@@ -750,4 +914,82 @@ mod test {
919+ fn test_behaviour_when_moving_to_end_of_next_long_words() {
920+ let tests = array::IntoIter::new([
921+ ("Basic forward motion from the start of a word to the end of it",
922+ vec![(1, Range::new(0, 0), Range::new(0, 4))]),
923+ ("Basic forward motion from the end of a word to the end of the next",
924+ vec![(1, Range::new(0, 4), Range::new(5, 12))]),
925+ ("Basic forward motion from the middle of a word to the end of it",
926+ vec![(1, Range::new(2, 2), Range::new(2, 4))]),
927+ (" Jumping to end of a word preceded by whitespace",
928+ vec![(1, Range::new(0, 0), Range::new(0, 10))]),
929+ (" Starting from a boundary advances the anchor",
930+ vec![(1, Range::new(0, 0), Range::new(1, 8))]),
931+ ("Previous anchor is irrelevant for end of word motion",
932+ vec![(1, Range::new(12, 2), Range::new(2, 7))]),
933+ ("Identifiers_with_underscores are considered a single word",
934+ vec![(1, Range::new(0, 0), Range::new(0, 27))]),
935+ ("Jumping\n into starting whitespace selects up to the end of next word",
936+ vec![(1, Range::new(0, 6), Range::new(8, 15))]),
937+ ("alphanumeric.!,and.?=punctuation are treated the same way",
939+ (1, Range::new(0, 0), Range::new(0, 31)),
941+ ("... ... punctuation and spaces behave as expected",
943+ (1, Range::new(0, 0), Range::new(0, 2)),
944+ (1, Range::new(0, 2), Range::new(3, 8)),
946+ (".._.._ punctuation is joined by underscores into a single block",
947+ vec![(1, Range::new(0, 0), Range::new(0, 5))]),
948+ ("Newlines\n\nare bridged seamlessly.",
950+ (1, Range::new(0, 0), Range::new(0, 7)),
951+ (1, Range::new(0, 7), Range::new(10, 12)),
953+ ("Jumping\n\n\n\n\n\n from newlines to whitespace selects to end of next word.",
955+ (1, Range::new(0, 8), Range::new(13, 19)),
957+ ("A failed motion does not modify the range",
959+ (3, Range::new(37, 41), Range::new(37, 41)),
961+ ("Multiple motions at once resolve correctly",
963+ (3, Range::new(0, 0), Range::new(16, 18)),
965+ ("Excessive motions are performed partially",
967+ (999, Range::new(0, 0), Range::new(31, 40)),
969+ ("", // Edge case of moving forward in empty string
971+ (1, Range::new(0, 0), Range::new(0, 0)),
973+ ("\n\n\n\n\n", // Edge case of moving forward in all newlines
975+ (1, Range::new(0, 0), Range::new(0, 4)),
977+ ("\n \n \n Jumping through alternated space blocks and newlines selects the space blocks",
979+ (1, Range::new(0, 0), Range::new(1, 3)),
980+ (1, Range::new(1, 3), Range::new(5, 7)),
982+ ("ヒーリ..クス multibyte characters behave as normal characters, including when they interact with punctuation",
984+ (1, Range::new(0, 0), Range::new(0, 6)),
988+ for (sample, scenario) in tests {
989+ for (count, begin, expected_end) in scenario.into_iter() {
990+ let range = move_next_long_word_end(Rope::from(sample).slice(..), begin, count);
991+ assert_eq!(range, expected_end, "Case failed: [{}]", sample);