Fix changeset composition, lengths don't have to match.

pull/4/head
Blaž Hrastnik 4 years ago
parent b765c17896
commit eba5b1ef33

@ -45,10 +45,12 @@ impl ChangeSet {
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
/// returned value will represent the change `docA` → `docC`. /// returned value will represent the change `docA` → `docC`.
pub fn compose(self, other: ChangeSet) -> Result<Self, ()> { pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
if self.len != other.len { // TODO: len before should match len after
// length mismatch
return Err(()); // if self.len != other.len {
} // // length mismatch
// return Err(());
// }
let len = self.changes.len(); let len = self.changes.len();
@ -477,23 +479,23 @@ mod test {
Insert("!".into()), Insert("!".into()),
Retain(1), Retain(1),
Delete(2), Delete(2),
Insert("ab".into()), Insert("abc".into()),
], ],
len: 7, len: 8,
}; };
let b = ChangeSet { let b = ChangeSet {
changes: vec![Delete(5), Insert("world".into()), Retain(4)], changes: vec![Delete(5), Insert("world".into()), Retain(5)],
len: 7, len: 9,
}; };
let mut text = Rope::from("hello xz"); let mut text = Rope::from("hello xz");
// should probably return cloned text // should probably return cloned text
a.compose(b).unwrap().apply(&mut text); let composed = a.compose(b).unwrap();
assert_eq!(composed.len, 8);
// unimplemented!("{:?}", text); assert!(composed.apply(&mut text));
// TODO: assert assert_eq!(text, "world! abc");
} }
#[test] #[test]

Loading…
Cancel
Save