fix(sdk): Fix a substract with overflow in LinkedChunk.

This commit is contained in:
Ivan Enderlin
2024-06-19 12:16:18 +02:00
parent 6340eeac0b
commit edcd573b6f
@@ -1029,7 +1029,7 @@ impl<const CAPACITY: usize, Item, Gap> Chunk<CAPACITY, Item, Gap> {
match &self.content {
ChunkContent::Gap(..) => Position(identifier, 0),
ChunkContent::Items(items) => Position(identifier, items.len() - 1),
ChunkContent::Items(items) => Position(identifier, items.len().saturating_sub(1)),
}
}
@@ -1606,6 +1606,14 @@ mod tests {
assert_matches!(iterator.next(), None);
}
#[test]
fn test_ritems_empty() {
let linked_chunk = LinkedChunk::<2, char, ()>::new();
let mut iterator = linked_chunk.ritems();
assert_matches!(iterator.next(), None);
}
#[test]
fn test_items() {
let mut linked_chunk = LinkedChunk::<2, char, ()>::new();
@@ -1623,6 +1631,14 @@ mod tests {
assert_matches!(iterator.next(), None);
}
#[test]
fn test_items_empty() {
let linked_chunk = LinkedChunk::<2, char, ()>::new();
let mut iterator = linked_chunk.items();
assert_matches!(iterator.next(), None);
}
#[test]
fn test_ritems_from() -> Result<(), Error> {
let mut linked_chunk = LinkedChunk::<2, char, ()>::new();