mirror of
https://github.com/loro-dev/loro.git
synced 2024-11-28 17:41:49 +00:00
fix: cursor get_sliced should have len > 0
This commit is contained in:
parent
5bcaf4c58a
commit
9d31605bde
2 changed files with 21 additions and 1 deletions
|
@ -173,7 +173,7 @@ impl ListContainer {
|
|||
pub fn get(&self, pos: usize) -> Option<LoroValue> {
|
||||
self.state
|
||||
.get(pos)
|
||||
.map(|range| self.raw_data.slice(&range.get_sliced().0))
|
||||
.map(|range| self.raw_data.slice(&range.get_sliced_with_len(1).0))
|
||||
.and_then(|slice| slice.first().cloned())
|
||||
}
|
||||
|
||||
|
@ -685,3 +685,18 @@ impl ContainerWrapper for List {
|
|||
self.client_id
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::LoroCore;
|
||||
|
||||
#[test]
|
||||
fn test_list_get() {
|
||||
let mut loro = LoroCore::default();
|
||||
let mut list = loro.get_list("id");
|
||||
list.insert(&loro, 0, 123).unwrap();
|
||||
list.insert(&loro, 1, 123).unwrap();
|
||||
assert_eq!(list.get(0), Some(123.into()));
|
||||
assert_eq!(list.get(1), Some(123.into()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -377,9 +377,14 @@ impl<'tree, T: Rle, A: RleTreeTrait<T>, M> RawSafeCursor<'tree, T, A, M> {
|
|||
}
|
||||
|
||||
pub fn get_sliced(&self) -> T {
|
||||
assert_ne!(self.0.len, 0);
|
||||
self.as_ref()
|
||||
.slice(self.0.offset, self.0.offset + self.0.len)
|
||||
}
|
||||
|
||||
pub fn get_sliced_with_len(&self, len: usize) -> T {
|
||||
self.as_ref().slice(self.0.offset, self.0.offset + len)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tree, T: Rle, A: RleTreeTrait<T>, M> GetOp for RawSafeCursor<'tree, T, A, M> {
|
||||
|
|
Loading…
Reference in a new issue