fix: op iter bug

This commit is contained in:
Zixuan Chen 2022-11-17 23:44:57 +08:00
parent e7b1148c8a
commit 3b42c06a01
5 changed files with 21 additions and 50 deletions

View file

@ -649,12 +649,25 @@ mod test {
#[test]
fn case_two() {
test_multi_sites(
2,
&mut [Ins {
content: 123,
pos: 0,
site: 1,
}],
3,
&mut [
Ins {
content: 35108,
pos: 0,
site: 2,
},
Ins {
content: 4626,
pos: 0,
site: 4,
},
SyncAll,
Ins {
content: 65462,
pos: 7,
site: 4,
},
],
)
}

View file

@ -94,8 +94,8 @@ impl<'a> Iterator for OpSpanIter<'a> {
let op = RichOp::new_by_slice_on_change(
change,
op,
self.span.counter.min(),
self.span.counter.end(),
self.span.counter.min() - change.id.counter,
self.span.counter.end() - change.id.counter,
);
if op.atom_len() == 0 {
return None;

View file

@ -1,6 +1,5 @@
use ctor::ctor;
pub mod tests;
use loro_core::container::registry::ContainerWrapper;
use loro_core::{LoroCore, LoroValue};

View file

@ -1 +0,0 @@
pub mod task;

View file

@ -1,40 +0,0 @@
use std::io::Read;
use flate2::read::GzDecoder;
use loro_core::container::registry::ContainerWrapper;
use loro_core::LoroCore;
use serde_json::Value;
const RAW_DATA: &[u8; 901823] = include_bytes!("../../benches/automerge-paper.json.gz");
#[test]
pub fn automerge_direct_sync() {
let mut d = GzDecoder::new(&RAW_DATA[..]);
let mut s = String::new();
d.read_to_string(&mut s).unwrap();
let json: Value = serde_json::from_str(&s).unwrap();
let txns = json.as_object().unwrap().get("txns");
let mut loro = LoroCore::default();
let mut loro_b = LoroCore::default();
for txn in txns.unwrap().as_array().unwrap() {
let text = loro.get_text("text");
text.with_container(|text| {
let patches = txn
.as_object()
.unwrap()
.get("patches")
.unwrap()
.as_array()
.unwrap();
for patch in patches {
let pos = patch[0].as_u64().unwrap() as usize;
let del_here = patch[1].as_u64().unwrap() as usize;
let ins_content = patch[2].as_str().unwrap();
text.delete(&loro, pos, del_here);
text.insert(&loro, pos, ins_content);
}
});
loro_b.import(loro.export(loro_b.vv()));
}
}