Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- documented safety rationale for `winnow` integration
- implemented `Stream` directly for `Bytes` with a safe `iter_offsets` iterator
- added `pop_back` and `pop_front` helpers and rewrote parser examples
- added tests covering `pop_front` and `pop_back`
- removed the Completed Work section from `INVENTORY.md` and documented its use
- added `Bytes::try_unwrap_owner` to reclaim the owner when uniquely held
- simplified `Bytes::try_unwrap_owner` implementation
Expand Down
2 changes: 1 addition & 1 deletion INVENTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
- `ByteSource` implementation for `VecDeque<u8>` to support ring buffers.

## Discovered Issues
- Missing tests for `pop_front` and `pop_back` helpers.
- None at the moment.
20 changes: 20 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ fn test_slice_to_bytes_unrelated_slice() {
assert!(bytes.slice_to_bytes(slice).is_none());
}

#[test]
fn test_pop_front() {
let mut bytes = Bytes::from(b"abc".to_vec());
assert_eq!(bytes.pop_front(), Some(b'a'));
assert_eq!(bytes.as_ref(), b"bc");
assert_eq!(bytes.pop_front(), Some(b'b'));
assert_eq!(bytes.pop_front(), Some(b'c'));
assert_eq!(bytes.pop_front(), None);
}

#[test]
fn test_pop_back() {
let mut bytes = Bytes::from(b"abc".to_vec());
assert_eq!(bytes.pop_back(), Some(b'c'));
assert_eq!(bytes.as_ref(), b"ab");
assert_eq!(bytes.pop_back(), Some(b'b'));
assert_eq!(bytes.pop_back(), Some(b'a'));
assert_eq!(bytes.pop_back(), None);
}

#[test]
fn test_weakbytes_multiple_upgrades() {
let bytes = Bytes::from(b"hello".to_vec());
Expand Down