@@ -3093,26 +3093,36 @@ mod tests {
3093
3093
3094
3094
#[ test]
3095
3095
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 ( ) ;
3097
3099
3098
3100
linked_chunk. push_items_back ( [ 'a' , 'b' , 'c' ] ) ;
3099
3101
linked_chunk. push_gap_back ( ( ) ) ;
3100
3102
// Sanity check.
3101
3103
assert_items_eq ! ( linked_chunk, [ 'a' , 'b' , 'c' ] [ -] ) ;
3102
3104
3105
+ // Drain previous updates.
3106
+ let _ = linked_chunk. updates ( ) . unwrap ( ) . take ( ) ;
3107
+
3103
3108
// 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 ( ) ;
3105
3110
assert_items_eq ! ( linked_chunk, [ 'a' , 'B' , 'c' ] [ -] ) ;
3106
3111
3112
+ assert_eq ! (
3113
+ linked_chunk. updates( ) . unwrap( ) . take( ) ,
3114
+ & [ ReplaceItem { at: Position ( ChunkIdentifier ( 0 ) , 1 ) , item: 'B' } ]
3115
+ ) ;
3116
+
3107
3117
// Attempt to replace out-of-bounds.
3108
3118
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' ) ,
3110
3120
Err ( Error :: InvalidItemIndex { index: 3 } )
3111
3121
) ;
3112
3122
3113
3123
// Attempt to replace gap.
3114
3124
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' ) ,
3116
3126
Err ( Error :: ChunkIsAGap { .. } )
3117
3127
) ;
3118
3128
}
0 commit comments