Skip to content

Commit 8a60b79

Browse files
committed
add merge test
1 parent bbf41d2 commit 8a60b79

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

helix-core/src/history.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ impl std::str::FromStr for UndoKind {
547547

548548
#[cfg(test)]
549549
mod test {
550+
use std::io::Cursor;
551+
550552
use quickcheck::quickcheck;
551553

552554
use super::*;
@@ -794,6 +796,31 @@ mod test {
794796
);
795797
}
796798

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+
797824
quickcheck!(
798825
fn serde_history(original: String, changes_a: Vec<String>, changes_b: Vec<String>) -> bool {
799826
fn create_changes(history: &mut History, doc: &mut Rope, changes: Vec<String>) {
@@ -812,7 +839,7 @@ mod test {
812839
let mut original = Rope::from(original);
813840

814841
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());
816843
let file = tempfile::NamedTempFile::new().unwrap();
817844
history.serialize(&mut cursor, file.path(), 0, 0).unwrap();
818845
cursor.set_position(0);

helix-view/src/document.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,10 @@ mod test {
15981598
.collect();
15991599

16001600
let file = tempfile::NamedTempFile::new().unwrap();
1601-
let mut config = Config::default();
1602-
config.persistent_undo = true;
1601+
let config = Config {
1602+
persistent_undo: true,
1603+
..Default::default()
1604+
};
16031605

16041606
let view_id = ViewId::default();
16051607
let config = Arc::new(ArcSwap::new(Arc::new(config)));
@@ -1613,7 +1615,7 @@ mod test {
16131615
helix_lsp::block_on(doc_1.save::<PathBuf>(None, true).unwrap()).unwrap();
16141616

16151617
let mut doc_2 = Document::open(file.path(), None, None, config.clone()).unwrap();
1616-
let mut doc_3 = Document::open(file.path(), None, None, config.clone()).unwrap();
1618+
let mut doc_3 = Document::open(file.path(), None, None, config).unwrap();
16171619
doc_2.ensure_view_init(view_id);
16181620
doc_3.ensure_view_init(view_id);
16191621

0 commit comments

Comments
 (0)