Skip to content

Commit 8eb4b92

Browse files
Merge pull request #7 from triblespace/codex/add-unit-tests-for-slice_to_bytes
Add slice_to_bytes tests
2 parents 7d39243 + 89836a3 commit 8eb4b92

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,18 @@ fn test_downgrade_upgrade() {
6161
let b3 = wb.upgrade();
6262
assert!(b3.is_none());
6363
}
64+
#[test]
65+
fn test_slice_to_bytes_same_source() {
66+
let bytes = Bytes::from(b"abcdef".to_vec());
67+
let slice = &bytes[1..4];
68+
let result = bytes.slice_to_bytes(slice).expect("slice from same bytes");
69+
assert_eq!(result, bytes.slice(1..4));
70+
}
71+
72+
#[test]
73+
fn test_slice_to_bytes_unrelated_slice() {
74+
let bytes = Bytes::from(b"abcdef".to_vec());
75+
let other = b"xyz123".to_vec();
76+
let slice = &other[1..4];
77+
assert!(bytes.slice_to_bytes(slice).is_none());
78+
}

0 commit comments

Comments
 (0)