@@ -624,6 +624,9 @@ impl GraphemeCursor {
624624if self . offset ==0 {
625625return Ok ( None ) ;
626626}
627+ if self . offset == chunk_start{
628+ return Err ( GraphemeIncomplete :: PrevChunk ) ;
629+ }
627630let mut iter = chunk[ ..self . offset - chunk_start] . chars ( ) . rev ( ) ;
628631let mut ch = iter. next ( ) . unwrap ( ) ;
629632loop {
@@ -647,6 +650,7 @@ impl GraphemeCursor {
647650self . decide ( true ) ;
648651} else {
649652self . resuming =true ;
653+ self . cat_after =Some ( gr:: grapheme_category ( ch) ) ;
650654return Err ( GraphemeIncomplete :: PrevChunk ) ;
651655}
652656}
@@ -659,3 +663,19 @@ impl GraphemeCursor {
659663}
660664}
661665}
666+
667+ #[ test]
668+ fn test_grapheme_cursor_prev_boundary ( ) {
669+ let s ="abcd" ;
670+ let mut c =GraphemeCursor :: new ( 3 , s. len ( ) , true ) ;
671+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
672+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 2 ) ) ) ;
673+ }
674+
675+ #[ test]
676+ fn test_grapheme_cursor_prev_boundary_chunk_start ( ) {
677+ let s ="abcd" ;
678+ let mut c =GraphemeCursor :: new ( 2 , s. len ( ) , true ) ;
679+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
680+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 1 ) ) ) ;
681+ }