on master help sign in
Fix changeset composition, lengths don't have to match.
eba5b1eBlaž Hrastnik
helix-core/src/transaction.rs+14−12
@@ -45,10 +45,12 @@ impl ChangeSet {
45 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
45 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
46 /// returned value will represent the change `docA` → `docC`.
46 /// returned value will represent the change `docA` → `docC`.
47 pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
47 pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
48+ // TODO: len before should match len after
49+
48− if self.len != other.len {
50+ // if self.len != other.len {
49− // length mismatch
51+ // // length mismatch
50− return Err(());
52+ // return Err(());
51− }
53+ // }
52
54
53 let len = self.changes.len();
55 let len = self.changes.len();
54
56
@@ -477,23 +479,23 @@ mod test {
477 Insert("!".into()),
479 Insert("!".into()),
478 Retain(1),
480 Retain(1),
479 Delete(2),
481 Delete(2),
480− Insert("ab".into()),
482+ Insert("abc".into()),
481 ],
483 ],
482− len: 7,
484+ len: 8,
483 };
485 };
484
486
485 let b = ChangeSet {
487 let b = ChangeSet {
486− changes: vec![Delete(5), Insert("world".into()), Retain(4)],
488+ changes: vec![Delete(5), Insert("world".into()), Retain(5)],
487− len: 7,
489+ len: 9,
488 };
490 };
489
491
490 let mut text = Rope::from("hello xz");
492 let mut text = Rope::from("hello xz");
491
493
492 // should probably return cloned text
494 // should probably return cloned text
493− a.compose(b).unwrap().apply(&mut text);
495+ let composed = a.compose(b).unwrap();
494−
496+ assert_eq!(composed.len, 8);
495− // unimplemented!("{:?}", text);
497+ assert!(composed.apply(&mut text));
496− // TODO: assert
498+ assert_eq!(text, "world! abc");
497 }
499 }
498
500
499 #[test]
501 #[test]