diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/bytes-0.4.9/tests/test_buf.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/bytes-0.4.9/tests/test_buf.rs')
-rw-r--r-- | third_party/rust/bytes-0.4.9/tests/test_buf.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/third_party/rust/bytes-0.4.9/tests/test_buf.rs b/third_party/rust/bytes-0.4.9/tests/test_buf.rs new file mode 100644 index 0000000000..f25c25f2b5 --- /dev/null +++ b/third_party/rust/bytes-0.4.9/tests/test_buf.rs @@ -0,0 +1,58 @@ +extern crate bytes; +extern crate byteorder; +extern crate iovec; + +use bytes::Buf; +use iovec::IoVec; +use std::io::Cursor; + +#[test] +fn test_fresh_cursor_vec() { + let mut buf = Cursor::new(b"hello".to_vec()); + + assert_eq!(buf.remaining(), 5); + assert_eq!(buf.bytes(), b"hello"); + + buf.advance(2); + + assert_eq!(buf.remaining(), 3); + assert_eq!(buf.bytes(), b"llo"); + + buf.advance(3); + + assert_eq!(buf.remaining(), 0); + assert_eq!(buf.bytes(), b""); +} + +#[test] +fn test_get_u8() { + let mut buf = Cursor::new(b"\x21zomg"); + assert_eq!(0x21, buf.get_u8()); +} + +#[test] +fn test_get_u16() { + let buf = b"\x21\x54zomg"; + assert_eq!(0x2154, Cursor::new(buf).get_u16_be()); + assert_eq!(0x5421, Cursor::new(buf).get_u16_le()); +} + +#[test] +#[should_panic] +fn test_get_u16_buffer_underflow() { + let mut buf = Cursor::new(b"\x21"); + buf.get_u16_be(); +} + +#[test] +fn test_bufs_vec() { + let buf = Cursor::new(b"hello world"); + + let b1: &[u8] = &mut [0]; + let b2: &[u8] = &mut [0]; + + let mut dst: [&IoVec; 2] = + [b1.into(), b2.into()]; + + assert_eq!(1, buf.bytes_vec(&mut dst[..])); +} |