Skip to content

Commit 95797e9

Browse files
Merge pull request #53 from triblespace/codex/determine-next-steps-for-project-advancement
Add tests for prefix and suffix helpers
2 parents 064cc4e + 1b12bca commit 95797e9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- implemented `Stream` directly for `Bytes` with a safe `iter_offsets` iterator
3737
- added `pop_back` and `pop_front` helpers and rewrote parser examples
3838
- added tests covering `pop_front` and `pop_back`
39+
- added tests covering `take_prefix` and `take_suffix`
3940
- removed the Completed Work section from `INVENTORY.md` and documented its use
4041
- added `Bytes::try_unwrap_owner` to reclaim the owner when uniquely held
4142
- simplified `Bytes::try_unwrap_owner` implementation

INVENTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## Desired Functionality
77
- Add Kani proofs for winnow view helpers.
8+
- Implement `ExactSizeIterator` or `FusedIterator` for `BytesIterOffsets` to simplify iteration.
89

910
## Discovered Issues
1011
- None at the moment.

src/tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ fn test_pop_back() {
174174
assert_eq!(bytes.pop_back(), None);
175175
}
176176

177+
#[test]
178+
fn test_take_prefix() {
179+
let mut bytes = Bytes::from(b"abcdef".to_vec());
180+
let prefix = bytes.take_prefix(2).expect("prefix");
181+
assert_eq!(prefix.as_ref(), b"ab");
182+
assert_eq!(bytes.as_ref(), b"cdef");
183+
assert!(bytes.take_prefix(10).is_none());
184+
}
185+
186+
#[test]
187+
fn test_take_suffix() {
188+
let mut bytes = Bytes::from(b"abcdef".to_vec());
189+
let suffix = bytes.take_suffix(2).expect("suffix");
190+
assert_eq!(suffix.as_ref(), b"ef");
191+
assert_eq!(bytes.as_ref(), b"abcd");
192+
assert!(bytes.take_suffix(10).is_none());
193+
}
194+
177195
#[test]
178196
fn test_weakbytes_multiple_upgrades() {
179197
let bytes = Bytes::from(b"hello".to_vec());

0 commit comments

Comments
 (0)