From 8a60b79a2c9e279d8ad4bcc3b6e61940b0a7b3f6 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Sun, 19 Feb 2023 21:16:12 -0500 Subject: [PATCH] add merge test --- helix-core/src/history.rs | 29 ++++++++++++++++++++++++++++- helix-view/src/document.rs | 8 +++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 04b03974aa53..c8418a7f51da 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -547,6 +547,8 @@ impl std::str::FromStr for UndoKind { #[cfg(test)] mod test { + use std::io::Cursor; + use quickcheck::quickcheck; use super::*; @@ -794,6 +796,31 @@ mod test { ); } + #[test] + fn merge_history() { + let file = tempfile::NamedTempFile::new().unwrap(); + let mut undo = Cursor::new(Vec::new()); + let mut history_1 = History::default(); + let mut history_2 = History::default(); + + let state = State { + doc: Rope::new(), + selection: Selection::point(0), + }; + let tx = Transaction::change( + &Rope::new(), + [(0, 0, Some("Hello, world!".into()))].into_iter(), + ); + history_1.commit_revision(&tx, &state); + history_1.serialize(&mut undo, file.path(), 0, 0).unwrap(); + undo.seek(SeekFrom::Start(0)).unwrap(); + + let saved_history = History::deserialize(&mut undo, file.path()).unwrap().1; + history_2.merge(saved_history, 1).unwrap(); + + assert_eq!(history_1.revisions, history_2.revisions); + } + quickcheck!( fn serde_history(original: String, changes_a: Vec, changes_b: Vec) -> bool { fn create_changes(history: &mut History, doc: &mut Rope, changes: Vec) { @@ -812,7 +839,7 @@ mod test { let mut original = Rope::from(original); create_changes(&mut history, &mut original, changes_a); - let mut cursor = std::io::Cursor::new(Vec::new()); + let mut cursor = Cursor::new(Vec::new()); let file = tempfile::NamedTempFile::new().unwrap(); history.serialize(&mut cursor, file.path(), 0, 0).unwrap(); cursor.set_position(0); diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 77175820c569..2c6f64c6c41a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1598,8 +1598,10 @@ mod test { .collect(); let file = tempfile::NamedTempFile::new().unwrap(); - let mut config = Config::default(); - config.persistent_undo = true; + let config = Config { + persistent_undo: true, + ..Default::default() + }; let view_id = ViewId::default(); let config = Arc::new(ArcSwap::new(Arc::new(config))); @@ -1613,7 +1615,7 @@ mod test { helix_lsp::block_on(doc_1.save::(None, true).unwrap()).unwrap(); let mut doc_2 = Document::open(file.path(), None, None, config.clone()).unwrap(); - let mut doc_3 = Document::open(file.path(), None, None, config.clone()).unwrap(); + let mut doc_3 = Document::open(file.path(), None, None, config).unwrap(); doc_2.ensure_view_init(view_id); doc_3.ensure_view_init(view_id);