@@ -547,6 +547,8 @@ impl std::str::FromStr for UndoKind {
547
547
548
548
#[ cfg( test) ]
549
549
mod test {
550
+ use std:: io:: Cursor ;
551
+
550
552
use quickcheck:: quickcheck;
551
553
552
554
use super :: * ;
@@ -794,6 +796,31 @@ mod test {
794
796
) ;
795
797
}
796
798
799
+ #[ test]
800
+ fn merge_history ( ) {
801
+ let file = tempfile:: NamedTempFile :: new ( ) . unwrap ( ) ;
802
+ let mut undo = Cursor :: new ( Vec :: new ( ) ) ;
803
+ let mut history_1 = History :: default ( ) ;
804
+ let mut history_2 = History :: default ( ) ;
805
+
806
+ let state = State {
807
+ doc : Rope :: new ( ) ,
808
+ selection : Selection :: point ( 0 ) ,
809
+ } ;
810
+ let tx = Transaction :: change (
811
+ & Rope :: new ( ) ,
812
+ [ ( 0 , 0 , Some ( "Hello, world!" . into ( ) ) ) ] . into_iter ( ) ,
813
+ ) ;
814
+ history_1. commit_revision ( & tx, & state) ;
815
+ history_1. serialize ( & mut undo, file. path ( ) , 0 , 0 ) . unwrap ( ) ;
816
+ undo. seek ( SeekFrom :: Start ( 0 ) ) . unwrap ( ) ;
817
+
818
+ let saved_history = History :: deserialize ( & mut undo, file. path ( ) ) . unwrap ( ) . 1 ;
819
+ history_2. merge ( saved_history, 1 ) . unwrap ( ) ;
820
+
821
+ assert_eq ! ( history_1. revisions, history_2. revisions) ;
822
+ }
823
+
797
824
quickcheck ! (
798
825
fn serde_history( original: String , changes_a: Vec <String >, changes_b: Vec <String >) -> bool {
799
826
fn create_changes( history: & mut History , doc: & mut Rope , changes: Vec <String >) {
@@ -812,7 +839,7 @@ mod test {
812
839
let mut original = Rope :: from( original) ;
813
840
814
841
create_changes( & mut history, & mut original, changes_a) ;
815
- let mut cursor = std :: io :: Cursor :: new( Vec :: new( ) ) ;
842
+ let mut cursor = Cursor :: new( Vec :: new( ) ) ;
816
843
let file = tempfile:: NamedTempFile :: new( ) . unwrap( ) ;
817
844
history. serialize( & mut cursor, file. path( ) , 0 , 0 ) . unwrap( ) ;
818
845
cursor. set_position( 0 ) ;
0 commit comments