@@ -3093,26 +3093,36 @@ mod tests {
30933093
30943094 #[ test]
30953095 fn test_replace_item ( ) {
3096- let mut linked_chunk = LinkedChunk :: < 3 , char , ( ) > :: new ( ) ;
3096+ use super :: Update :: * ;
3097+
3098+ let mut linked_chunk = LinkedChunk :: < 3 , char , ( ) > :: new_with_update_history ( ) ;
30973099
30983100 linked_chunk. push_items_back ( [ 'a' , 'b' , 'c' ] ) ;
30993101 linked_chunk. push_gap_back ( ( ) ) ;
31003102 // Sanity check.
31013103 assert_items_eq ! ( linked_chunk, [ 'a' , 'b' , 'c' ] [ -] ) ;
31023104
3105+ // Drain previous updates.
3106+ let _ = linked_chunk. updates ( ) . unwrap ( ) . take ( ) ;
3107+
31033108 // Replace item in bounds.
3104- linked_chunk. replace_item_at ( Position ( ChunkIdentifier :: new ( 0 ) , 1 ) , 'B' ) . unwrap ( ) ;
3109+ linked_chunk. replace_item_at ( Position ( ChunkIdentifier ( 0 ) , 1 ) , 'B' ) . unwrap ( ) ;
31053110 assert_items_eq ! ( linked_chunk, [ 'a' , 'B' , 'c' ] [ -] ) ;
31063111
3112+ assert_eq ! (
3113+ linked_chunk. updates( ) . unwrap( ) . take( ) ,
3114+ & [ ReplaceItem { at: Position ( ChunkIdentifier ( 0 ) , 1 ) , item: 'B' } ]
3115+ ) ;
3116+
31073117 // Attempt to replace out-of-bounds.
31083118 assert_matches ! (
3109- linked_chunk. replace_item_at( Position ( ChunkIdentifier :: new ( 0 ) , 3 ) , 'Z' ) ,
3119+ linked_chunk. replace_item_at( Position ( ChunkIdentifier ( 0 ) , 3 ) , 'Z' ) ,
31103120 Err ( Error :: InvalidItemIndex { index: 3 } )
31113121 ) ;
31123122
31133123 // Attempt to replace gap.
31143124 assert_matches ! (
3115- linked_chunk. replace_item_at( Position ( ChunkIdentifier :: new ( 1 ) , 0 ) , 'Z' ) ,
3125+ linked_chunk. replace_item_at( Position ( ChunkIdentifier ( 1 ) , 0 ) , 'Z' ) ,
31163126 Err ( Error :: ChunkIsAGap { .. } )
31173127 ) ;
31183128 }
0 commit comments