@@ -629,6 +629,9 @@ impl GraphemeCursor {
629
629
if self . offset == 0 {
630
630
return Ok ( None ) ;
631
631
}
632
+ if self . offset == chunk_start {
633
+ return Err ( GraphemeIncomplete :: PrevChunk ) ;
634
+ }
632
635
let mut iter = chunk[ ..self . offset - chunk_start] . chars ( ) . rev ( ) ;
633
636
let mut ch = iter. next ( ) . unwrap ( ) ;
634
637
loop {
@@ -652,6 +655,7 @@ impl GraphemeCursor {
652
655
self . decide ( true ) ;
653
656
} else {
654
657
self . resuming = true ;
658
+ self . cat_after = Some ( gr:: grapheme_category ( ch) ) ;
655
659
return Err ( GraphemeIncomplete :: PrevChunk ) ;
656
660
}
657
661
}
@@ -682,3 +686,19 @@ fn test_grapheme_cursor_chunk_start_require_precontext() {
682
686
c. provide_context ( & s[ ..1 ] , 0 ) ;
683
687
assert_eq ! ( c. is_boundary( & s[ 1 ..] , 1 ) , Ok ( false ) ) ;
684
688
}
689
+
690
+ #[ test]
691
+ fn test_grapheme_cursor_prev_boundary ( ) {
692
+ let s = "abcd" ;
693
+ let mut c = GraphemeCursor :: new ( 3 , s. len ( ) , true ) ;
694
+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
695
+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 2 ) ) ) ;
696
+ }
697
+
698
+ #[ test]
699
+ fn test_grapheme_cursor_prev_boundary_chunk_start ( ) {
700
+ let s = "abcd" ;
701
+ let mut c = GraphemeCursor :: new ( 2 , s. len ( ) , true ) ;
702
+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
703
+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 1 ) ) ) ;
704
+ }
0 commit comments