Skip to content

Commit b02fb7e

Browse files
Merge pull request #48 from triblespace/codex/determine-next-steps-for-project-advancement
Add tests for pop helpers
2 parents f49881c + a64698f commit b02fb7e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- documented safety rationale for `winnow` integration
3333
- implemented `Stream` directly for `Bytes` with a safe `iter_offsets` iterator
3434
- added `pop_back` and `pop_front` helpers and rewrote parser examples
35+
- added tests covering `pop_front` and `pop_back`
3536
- removed the Completed Work section from `INVENTORY.md` and documented its use
3637
- added `Bytes::try_unwrap_owner` to reclaim the owner when uniquely held
3738
- simplified `Bytes::try_unwrap_owner` implementation

INVENTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
- `ByteSource` implementation for `VecDeque<u8>` to support ring buffers.
1010

1111
## Discovered Issues
12-
- Missing tests for `pop_front` and `pop_back` helpers.
12+
- None at the moment.

src/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ fn test_slice_to_bytes_unrelated_slice() {
103103
assert!(bytes.slice_to_bytes(slice).is_none());
104104
}
105105

106+
#[test]
107+
fn test_pop_front() {
108+
let mut bytes = Bytes::from(b"abc".to_vec());
109+
assert_eq!(bytes.pop_front(), Some(b'a'));
110+
assert_eq!(bytes.as_ref(), b"bc");
111+
assert_eq!(bytes.pop_front(), Some(b'b'));
112+
assert_eq!(bytes.pop_front(), Some(b'c'));
113+
assert_eq!(bytes.pop_front(), None);
114+
}
115+
116+
#[test]
117+
fn test_pop_back() {
118+
let mut bytes = Bytes::from(b"abc".to_vec());
119+
assert_eq!(bytes.pop_back(), Some(b'c'));
120+
assert_eq!(bytes.as_ref(), b"ab");
121+
assert_eq!(bytes.pop_back(), Some(b'b'));
122+
assert_eq!(bytes.pop_back(), Some(b'a'));
123+
assert_eq!(bytes.pop_back(), None);
124+
}
125+
106126
#[test]
107127
fn test_weakbytes_multiple_upgrades() {
108128
let bytes = Bytes::from(b"hello".to_vec());

0 commit comments

Comments
 (0)