fune/third_party/rust/bytes/tests/test_buf.rs
Andreas Tolfsen fa6c2a6c1a bug 1598286: third_party: vendor Rust dependencies; r=remote-protocol-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D58766

--HG--
rename : third_party/rust/bytes/.cargo-checksum.json => third_party/rust/bytes-0.4.9/.cargo-checksum.json
rename : third_party/rust/bytes/CHANGELOG.md => third_party/rust/bytes-0.4.9/CHANGELOG.md
rename : third_party/rust/bytes/Cargo.toml => third_party/rust/bytes-0.4.9/Cargo.toml
rename : third_party/rust/bytes/README.md => third_party/rust/bytes-0.4.9/README.md
rename : third_party/rust/bytes/benches/bytes.rs => third_party/rust/bytes-0.4.9/benches/bytes.rs
rename : third_party/rust/bytes/ci/before_deploy.ps1 => third_party/rust/bytes-0.4.9/ci/before_deploy.ps1
rename : third_party/rust/bytes/ci/before_deploy.sh => third_party/rust/bytes-0.4.9/ci/before_deploy.sh
rename : third_party/rust/bytes/ci/install.sh => third_party/rust/bytes-0.4.9/ci/install.sh
rename : third_party/rust/bytes/ci/script.sh => third_party/rust/bytes-0.4.9/ci/script.sh
rename : third_party/rust/bytes/ci/tsan => third_party/rust/bytes-0.4.9/ci/tsan
rename : third_party/rust/bytes/src/buf/buf.rs => third_party/rust/bytes-0.4.9/src/buf/buf.rs
rename : third_party/rust/bytes/src/buf/buf_mut.rs => third_party/rust/bytes-0.4.9/src/buf/buf_mut.rs
rename : third_party/rust/bytes/src/buf/chain.rs => third_party/rust/bytes-0.4.9/src/buf/chain.rs
rename : third_party/rust/bytes/src/buf/from_buf.rs => third_party/rust/bytes-0.4.9/src/buf/from_buf.rs
rename : third_party/rust/bytes/src/buf/into_buf.rs => third_party/rust/bytes-0.4.9/src/buf/into_buf.rs
rename : third_party/rust/bytes/src/buf/iter.rs => third_party/rust/bytes-0.4.9/src/buf/iter.rs
rename : third_party/rust/bytes/src/buf/mod.rs => third_party/rust/bytes-0.4.9/src/buf/mod.rs
rename : third_party/rust/bytes/src/buf/reader.rs => third_party/rust/bytes-0.4.9/src/buf/reader.rs
rename : third_party/rust/bytes/src/buf/take.rs => third_party/rust/bytes-0.4.9/src/buf/take.rs
rename : third_party/rust/bytes/src/buf/writer.rs => third_party/rust/bytes-0.4.9/src/buf/writer.rs
rename : third_party/rust/bytes/src/bytes.rs => third_party/rust/bytes-0.4.9/src/bytes.rs
rename : third_party/rust/bytes/src/debug.rs => third_party/rust/bytes-0.4.9/src/debug.rs
rename : third_party/rust/bytes/src/lib.rs => third_party/rust/bytes-0.4.9/src/lib.rs
rename : third_party/rust/bytes/src/serde.rs => third_party/rust/bytes-0.4.9/src/serde.rs
rename : third_party/rust/bytes/tests/test_buf.rs => third_party/rust/bytes-0.4.9/tests/test_buf.rs
rename : third_party/rust/bytes/tests/test_buf_mut.rs => third_party/rust/bytes-0.4.9/tests/test_buf_mut.rs
rename : third_party/rust/bytes/tests/test_bytes.rs => third_party/rust/bytes-0.4.9/tests/test_bytes.rs
rename : third_party/rust/bytes/tests/test_chain.rs => third_party/rust/bytes-0.4.9/tests/test_chain.rs
rename : third_party/rust/bytes/tests/test_debug.rs => third_party/rust/bytes-0.4.9/tests/test_debug.rs
rename : third_party/rust/bytes/tests/test_from_buf.rs => third_party/rust/bytes-0.4.9/tests/test_from_buf.rs
rename : third_party/rust/bytes/tests/test_iter.rs => third_party/rust/bytes-0.4.9/tests/test_iter.rs
rename : third_party/rust/bytes/tests/test_serde.rs => third_party/rust/bytes-0.4.9/tests/test_serde.rs
rename : third_party/rust/bytes/tests/test_take.rs => third_party/rust/bytes-0.4.9/tests/test_take.rs
rename : third_party/rust/bytes/benches/bytes.rs => third_party/rust/bytes/benches/bytes_mut.rs
rename : third_party/rust/bytes/src/buf/buf.rs => third_party/rust/bytes/src/buf/buf_impl.rs
rename : third_party/rust/bytes/src/buf/chain.rs => third_party/rust/bytes/src/buf/ext/chain.rs
rename : third_party/rust/bytes/src/buf/reader.rs => third_party/rust/bytes/src/buf/ext/reader.rs
rename : third_party/rust/bytes/src/buf/take.rs => third_party/rust/bytes/src/buf/ext/take.rs
rename : third_party/rust/bytes/src/buf/writer.rs => third_party/rust/bytes/src/buf/ext/writer.rs
rename : third_party/rust/http/.cargo-checksum.json => third_party/rust/http-0.1.17/.cargo-checksum.json
rename : third_party/rust/http/CHANGELOG.md => third_party/rust/http-0.1.17/CHANGELOG.md
rename : third_party/rust/http/Cargo.toml => third_party/rust/http-0.1.17/Cargo.toml
rename : third_party/rust/http/benches/header_map/basic.rs => third_party/rust/http-0.1.17/benches/header_map/basic.rs
rename : third_party/rust/http/benches/header_map/mod.rs => third_party/rust/http-0.1.17/benches/header_map/mod.rs
rename : third_party/rust/http/benches/header_map/vec_map.rs => third_party/rust/http-0.1.17/benches/header_map/vec_map.rs
rename : third_party/rust/http/benches/header_value.rs => third_party/rust/http-0.1.17/benches/header_value.rs
rename : third_party/rust/http/benches/uri.rs => third_party/rust/http-0.1.17/benches/uri.rs
rename : third_party/rust/http/src/byte_str.rs => third_party/rust/http-0.1.17/src/byte_str.rs
rename : third_party/rust/http/src/convert.rs => third_party/rust/http-0.1.17/src/convert.rs
rename : third_party/rust/http/src/error.rs => third_party/rust/http-0.1.17/src/error.rs
rename : third_party/rust/http/src/extensions.rs => third_party/rust/http-0.1.17/src/extensions.rs
rename : third_party/rust/http/src/header/map.rs => third_party/rust/http-0.1.17/src/header/map.rs
rename : third_party/rust/http/src/header/mod.rs => third_party/rust/http-0.1.17/src/header/mod.rs
rename : third_party/rust/http/src/header/name.rs => third_party/rust/http-0.1.17/src/header/name.rs
rename : third_party/rust/http/src/header/value.rs => third_party/rust/http-0.1.17/src/header/value.rs
rename : third_party/rust/http/src/lib.rs => third_party/rust/http-0.1.17/src/lib.rs
rename : third_party/rust/http/src/method.rs => third_party/rust/http-0.1.17/src/method.rs
rename : third_party/rust/http/src/request.rs => third_party/rust/http-0.1.17/src/request.rs
rename : third_party/rust/http/src/response.rs => third_party/rust/http-0.1.17/src/response.rs
rename : third_party/rust/http/src/status.rs => third_party/rust/http-0.1.17/src/status.rs
rename : third_party/rust/http/src/uri/authority.rs => third_party/rust/http-0.1.17/src/uri/authority.rs
rename : third_party/rust/http/src/uri/builder.rs => third_party/rust/http-0.1.17/src/uri/builder.rs
rename : third_party/rust/http/src/uri/mod.rs => third_party/rust/http-0.1.17/src/uri/mod.rs
rename : third_party/rust/http/src/uri/path.rs => third_party/rust/http-0.1.17/src/uri/path.rs
rename : third_party/rust/http/src/uri/port.rs => third_party/rust/http-0.1.17/src/uri/port.rs
rename : third_party/rust/http/src/uri/scheme.rs => third_party/rust/http-0.1.17/src/uri/scheme.rs
rename : third_party/rust/http/src/uri/tests.rs => third_party/rust/http-0.1.17/src/uri/tests.rs
rename : third_party/rust/http/src/version.rs => third_party/rust/http-0.1.17/src/version.rs
rename : third_party/rust/http/tests/header_map.rs => third_party/rust/http-0.1.17/tests/header_map.rs
rename : third_party/rust/http/tests/header_map_fuzz.rs => third_party/rust/http-0.1.17/tests/header_map_fuzz.rs
rename : third_party/rust/http/tests/status_code.rs => third_party/rust/http-0.1.17/tests/status_code.rs
extra : moz-landing-system : lando
2020-01-07 13:28:57 +00:00

101 lines
2.2 KiB
Rust

#![deny(warnings, rust_2018_idioms)]
use bytes::Buf;
use std::io::IoSlice;
#[test]
fn test_fresh_cursor_vec() {
let mut buf = &b"hello"[..];
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 = &b"\x21zomg"[..];
assert_eq!(0x21, buf.get_u8());
}
#[test]
fn test_get_u16() {
let mut buf = &b"\x21\x54zomg"[..];
assert_eq!(0x2154, buf.get_u16());
let mut buf = &b"\x21\x54zomg"[..];
assert_eq!(0x5421, buf.get_u16_le());
}
#[test]
#[should_panic]
fn test_get_u16_buffer_underflow() {
let mut buf = &b"\x21"[..];
buf.get_u16();
}
#[test]
fn test_bufs_vec() {
let buf = &b"hello world"[..];
let b1: &[u8] = &mut [];
let b2: &[u8] = &mut [];
let mut dst = [IoSlice::new(b1), IoSlice::new(b2)];
assert_eq!(1, buf.bytes_vectored(&mut dst[..]));
}
#[test]
fn test_vec_deque() {
use std::collections::VecDeque;
let mut buffer: VecDeque<u8> = VecDeque::new();
buffer.extend(b"hello world");
assert_eq!(11, buffer.remaining());
assert_eq!(b"hello world", buffer.bytes());
buffer.advance(6);
assert_eq!(b"world", buffer.bytes());
buffer.extend(b" piece");
let mut out = [0; 11];
buffer.copy_to_slice(&mut out);
assert_eq!(b"world piece", &out[..]);
}
#[test]
fn test_deref_buf_forwards() {
struct Special;
impl Buf for Special {
fn remaining(&self) -> usize {
unreachable!("remaining");
}
fn bytes(&self) -> &[u8] {
unreachable!("bytes");
}
fn advance(&mut self, _: usize) {
unreachable!("advance");
}
fn get_u8(&mut self) -> u8 {
// specialized!
b'x'
}
}
// these should all use the specialized method
assert_eq!(Special.get_u8(), b'x');
assert_eq!((&mut Special as &mut dyn Buf).get_u8(), b'x');
assert_eq!((Box::new(Special) as Box<dyn Buf>).get_u8(), b'x');
assert_eq!(Box::new(Special).get_u8(), b'x');
}