Add optimal representation
This commit is contained in:
parent
e052aa46c4
commit
3da0673af6
5 changed files with 325 additions and 35 deletions
|
|
@ -3,7 +3,7 @@ mod example_document;
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use example_document::ExampleDocument;
|
||||
use reconcile_text::{BuiltinTokenizer, reconcile};
|
||||
use reconcile_text::{BuiltinTokenizer, EditedText, reconcile};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[test]
|
||||
|
|
@ -34,6 +34,36 @@ fn test_document_one_way_with_cursors() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_document_one_way_with_cursors_and_serialisation() {
|
||||
for doc in &get_all_documents() {
|
||||
let parent = doc.parent();
|
||||
let left_operations =
|
||||
EditedText::from_strings_with_tokenizer(&parent, &doc.left(), &*BuiltinTokenizer::Word);
|
||||
let right_operations = EditedText::from_strings_with_tokenizer(
|
||||
&parent,
|
||||
&doc.right(),
|
||||
&*BuiltinTokenizer::Word,
|
||||
);
|
||||
|
||||
let serialised_left = serde_yaml::from_str(
|
||||
&serde_yaml::to_string(&left_operations.serialise_as_change_set()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let serialised_right = serde_yaml::from_str(
|
||||
&serde_yaml::to_string(&right_operations.serialise_as_change_set()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let restored_left_operations =
|
||||
EditedText::from_change_set(&parent, serialised_left, &*BuiltinTokenizer::Word);
|
||||
let restored_right_operations =
|
||||
EditedText::from_change_set(&parent, serialised_right, &*BuiltinTokenizer::Word);
|
||||
|
||||
doc.assert_eq(&restored_left_operations.merge(restored_right_operations));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_document_inverse_way_without_cursors() {
|
||||
for doc in &get_all_documents() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue