Skip to content

Commit

Permalink
add merge test
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Feb 20, 2023
1 parent bbf41d2 commit 8a60b79
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
29 changes: 28 additions & 1 deletion helix-core/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ impl std::str::FromStr for UndoKind {

#[cfg(test)]
mod test {
use std::io::Cursor;

use quickcheck::quickcheck;

use super::*;
Expand Down Expand Up @@ -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<String>, changes_b: Vec<String>) -> bool {
fn create_changes(history: &mut History, doc: &mut Rope, changes: Vec<String>) {
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -1613,7 +1615,7 @@ mod test {
helix_lsp::block_on(doc_1.save::<PathBuf>(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);

Expand Down

0 comments on commit 8a60b79

Please sign in to comment.