Skip to content

Commit

Permalink
fix(codec): wrong pos when split array
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Aug 22, 2023
1 parent 606b0a5 commit b18a849
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions libs/jwst-codec/src/doc/codec/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ impl Content {
Ok((Self::String(left.to_string()), Self::String(right.to_string())))
}
Self::Json(vec) => {
let (left, right) = vec.split_at((diff + 1) as usize);
let (left, right) = vec.split_at(diff as usize);
Ok((Self::Json(left.to_owned()), Self::Json(right.to_owned())))
}
Self::Any(vec) => {
let (left, right) = vec.split_at((diff + 1) as usize);
let (left, right) = vec.split_at(diff as usize);
Ok((Self::Any(left.to_owned()), Self::Any(right.to_owned())))
}
Self::Deleted(len) => {
Expand Down Expand Up @@ -357,18 +357,18 @@ mod tests {
{
let (left, right) = contents[1].split(1).unwrap();
assert!(contents[1].splittable());
assert_eq!(left, Content::Json(vec![None, Some("test_1".to_string())]));
assert_eq!(right, Content::Json(vec![Some("test_2".to_string())]));
assert_eq!(left, Content::Json(vec![None]));
assert_eq!(
right,
Content::Json(vec![Some("test_1".to_string()), Some("test_2".to_string())])
);
}

{
let (left, right) = contents[2].split(1).unwrap();
assert!(contents[2].splittable());
assert_eq!(
left,
Content::Any(vec![Any::BigInt64(42), Any::String("Test Any".to_string())])
);
assert_eq!(right, Content::Any(vec![]));
assert_eq!(left, Content::Any(vec![Any::BigInt64(42)]));
assert_eq!(right, Content::Any(vec![Any::String("Test Any".to_string())]));
}

{
Expand Down
36 changes: 18 additions & 18 deletions libs/jwst-codec/src/doc/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,32 +596,32 @@ impl DocStore {
// need to split the item and delete the right part
// -----item-----
// ^start
let struct_info = &items[idx];
let id = struct_info.id();
let node = &items[idx];
let id = node.id();

if !struct_info.deleted() && id.clock < start {
if !node.deleted() && id.clock < start {
DocStore::split_node_at(items, idx, start - id.clock)?;
idx += 1;
}
};

while idx < items.len() {
let struct_info = items[idx].clone();
let id = struct_info.id();

if let Some(item) = struct_info.as_item().get() {
if !item.deleted() && id.clock < end {
// need to split the item
// -----item-----
// ^end
if end < id.clock + struct_info.len() {
DocStore::split_node_at(items, idx, end - id.clock)?;
}
let node = items[idx].clone();
let id = node.id();

if id.clock < end {
if !node.deleted() {
if let Some(item) = node.as_item().get() {
// need to split the item
// -----item-----
// ^end
if end < id.clock + node.len() {
DocStore::split_node_at(items, idx, end - id.clock)?;

Check warning on line 619 in libs/jwst-codec/src/doc/store.rs

View check run for this annotation

Codecov / codecov/patch

libs/jwst-codec/src/doc/store.rs#L619

Added line #L619 was not covered by tests
}

self.delete_set.add(client, id.clock, item.len());
Self::delete_item(item, None);
} else {
break;
self.delete_set.add(client, id.clock, item.len());
Self::delete_item(item, None);
}

Check warning on line 624 in libs/jwst-codec/src/doc/store.rs

View check run for this annotation

Codecov / codecov/patch

libs/jwst-codec/src/doc/store.rs#L624

Added line #L624 was not covered by tests
}
} else {
break;
Expand Down

0 comments on commit b18a849

Please sign in to comment.