aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-07-10 20:22:56 -0700
committerHaibo Huang <hhb@google.com>2020-07-10 20:22:56 -0700
commit815f544e751e7b3cdc563ca0c97849f7decf782f (patch)
treee039ea0f1d64aa1ce4ba6e632a638d4ad3c6af2b /tests
parent3ab24982d6da8a21528bd7ce8b2e675dd284b178 (diff)
downloadbytes-815f544e751e7b3cdc563ca0c97849f7decf782f.tar.gz
Upgrade rust/crates/bytes to 0.5.5
Change-Id: Ide2810cb2888de2899fd55127a81c685a5a037b6
Diffstat (limited to 'tests')
-rw-r--r--tests/test_buf.rs2
-rw-r--r--tests/test_buf_mut.rs14
-rw-r--r--tests/test_bytes.rs78
-rw-r--r--tests/test_bytes_vec_alloc.rs6
-rw-r--r--tests/test_chain.rs4
-rw-r--r--tests/test_iter.rs1
-rw-r--r--tests/test_reader.rs3
-rw-r--r--tests/test_serde.rs2
8 files changed, 92 insertions, 18 deletions
diff --git a/tests/test_buf.rs b/tests/test_buf.rs
index 12b75a4..26b95ae 100644
--- a/tests/test_buf.rs
+++ b/tests/test_buf.rs
@@ -1,6 +1,7 @@
#![deny(warnings, rust_2018_idioms)]
use bytes::Buf;
+#[cfg(feature = "std")]
use std::io::IoSlice;
#[test]
@@ -42,6 +43,7 @@ fn test_get_u16_buffer_underflow() {
buf.get_u16();
}
+#[cfg(feature = "std")]
#[test]
fn test_bufs_vec() {
let buf = &b"hello world"[..];
diff --git a/tests/test_buf_mut.rs b/tests/test_buf_mut.rs
index f002f7d..c70e209 100644
--- a/tests/test_buf_mut.rs
+++ b/tests/test_buf_mut.rs
@@ -1,8 +1,10 @@
#![deny(warnings, rust_2018_idioms)]
-use bytes::{buf::IoSliceMut, BufMut, BytesMut};
-use std::usize;
-use std::fmt::Write;
+#[cfg(feature = "std")]
+use bytes::buf::IoSliceMut;
+use bytes::{BufMut, BytesMut};
+use core::fmt::Write;
+use core::usize;
#[test]
fn test_vec_as_mut_buf() {
@@ -45,13 +47,12 @@ fn test_put_u16() {
}
#[test]
+#[should_panic(expected = "cannot advance")]
fn test_vec_advance_mut() {
- // Regression test for carllerche/bytes#108.
+ // Verify fix for #354
let mut buf = Vec::with_capacity(8);
unsafe {
buf.advance_mut(12);
- assert_eq!(buf.len(), 12);
- assert!(buf.capacity() >= 12, "capacity: {}", buf.capacity());
}
}
@@ -65,6 +66,7 @@ fn test_clone() {
assert!(buf != buf2);
}
+#[cfg(feature = "std")]
#[test]
fn test_bufs_vec_mut() {
let b1: &mut [u8] = &mut [];
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs
index 40fcae4..106fa6f 100644
--- a/tests/test_bytes.rs
+++ b/tests/test_bytes.rs
@@ -1,6 +1,6 @@
#![deny(warnings, rust_2018_idioms)]
-use bytes::{Bytes, BytesMut, Buf, BufMut};
+use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::usize;
@@ -44,7 +44,6 @@ fn test_layout() {
mem::size_of::<Option<BytesMut>>(),
"BytesMut should be same size as Option<BytesMut>",
);
-
}
#[test]
@@ -87,13 +86,11 @@ fn fmt_write() {
write!(a, "{}", &s[..64]).unwrap();
assert_eq!(a, s[..64].as_bytes());
-
let mut b = BytesMut::with_capacity(64);
write!(b, "{}", &s[..32]).unwrap();
write!(b, "{}", &s[32..64]).unwrap();
assert_eq!(b, s[..64].as_bytes());
-
let mut c = BytesMut::with_capacity(64);
write!(c, "{}", s).unwrap();
assert_eq!(c, s[..].as_bytes());
@@ -305,11 +302,13 @@ fn split_off_to_at_gt_len() {
assert!(panic::catch_unwind(move || {
let _ = make_bytes().split_to(5);
- }).is_err());
+ })
+ .is_err());
assert!(panic::catch_unwind(move || {
let _ = make_bytes().split_off(5);
- }).is_err());
+ })
+ .is_err());
}
#[test]
@@ -343,6 +342,72 @@ fn freeze_clone_unique() {
}
#[test]
+fn freeze_after_advance() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ b.advance(1);
+ assert_eq!(b, s[1..]);
+ let b = b.freeze();
+ // Verify fix for #352. Previously, freeze would ignore the start offset
+ // for BytesMuts in Vec mode.
+ assert_eq!(b, s[1..]);
+}
+
+#[test]
+fn freeze_after_advance_arc() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ // Make b Arc
+ let _ = b.split_to(0);
+ b.advance(1);
+ assert_eq!(b, s[1..]);
+ let b = b.freeze();
+ assert_eq!(b, s[1..]);
+}
+
+#[test]
+fn freeze_after_split_to() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ let _ = b.split_to(1);
+ assert_eq!(b, s[1..]);
+ let b = b.freeze();
+ assert_eq!(b, s[1..]);
+}
+
+#[test]
+fn freeze_after_truncate() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ b.truncate(7);
+ assert_eq!(b, s[..7]);
+ let b = b.freeze();
+ assert_eq!(b, s[..7]);
+}
+
+#[test]
+fn freeze_after_truncate_arc() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ // Make b Arc
+ let _ = b.split_to(0);
+ b.truncate(7);
+ assert_eq!(b, s[..7]);
+ let b = b.freeze();
+ assert_eq!(b, s[..7]);
+}
+
+#[test]
+fn freeze_after_split_off() {
+ let s = &b"abcdefgh"[..];
+ let mut b = BytesMut::from(s);
+ let _ = b.split_off(7);
+ assert_eq!(b, s[..7]);
+ let b = b.freeze();
+ assert_eq!(b, s[..7]);
+}
+
+#[test]
fn fns_defined_for_bytes_mut() {
let mut bytes = BytesMut::from(&b"hello world"[..]);
@@ -798,7 +863,6 @@ fn slice_ref_works() {
test_slice_ref(&bytes, 9, 9, b"");
}
-
#[test]
fn slice_ref_empty() {
let bytes = Bytes::from(&b""[..]);
diff --git a/tests/test_bytes_vec_alloc.rs b/tests/test_bytes_vec_alloc.rs
index dc007cf..418a9cd 100644
--- a/tests/test_bytes_vec_alloc.rs
+++ b/tests/test_bytes_vec_alloc.rs
@@ -39,7 +39,11 @@ unsafe impl GlobalAlloc for Ledger {
let off_ptr = (ptr as *mut usize).offset(-1);
let orig_size = off_ptr.read();
if orig_size != layout.size() {
- panic!("bad dealloc: alloc size was {}, dealloc size is {}", orig_size, layout.size());
+ panic!(
+ "bad dealloc: alloc size was {}, dealloc size is {}",
+ orig_size,
+ layout.size()
+ );
}
let new_layout = match Layout::from_size_align(layout.size() + USIZE_SIZE, 1) {
diff --git a/tests/test_chain.rs b/tests/test_chain.rs
index 332571d..82de7fc 100644
--- a/tests/test_chain.rs
+++ b/tests/test_chain.rs
@@ -1,7 +1,8 @@
#![deny(warnings, rust_2018_idioms)]
-use bytes::{Buf, BufMut, Bytes};
use bytes::buf::{BufExt, BufMutExt};
+use bytes::{Buf, BufMut, Bytes};
+#[cfg(feature = "std")]
use std::io::IoSlice;
#[test]
@@ -42,6 +43,7 @@ fn iterating_two_bufs() {
assert_eq!(res, &b"helloworld"[..]);
}
+#[cfg(feature = "std")]
#[test]
fn vectored_read() {
let a = Bytes::from(&b"hello"[..]);
diff --git a/tests/test_iter.rs b/tests/test_iter.rs
index 13b86cd..2302a69 100644
--- a/tests/test_iter.rs
+++ b/tests/test_iter.rs
@@ -11,7 +11,6 @@ fn iter_len() {
assert_eq!(iter.len(), 11);
}
-
#[test]
fn empty_iter_len() {
let buf = Bytes::from_static(b"");
diff --git a/tests/test_reader.rs b/tests/test_reader.rs
index 9c5972a..b5da2c9 100644
--- a/tests/test_reader.rs
+++ b/tests/test_reader.rs
@@ -1,8 +1,9 @@
#![deny(warnings, rust_2018_idioms)]
+#![cfg(feature = "std")]
use std::io::{BufRead, Read};
-use bytes::buf::{BufExt};
+use bytes::buf::BufExt;
#[test]
fn read() {
diff --git a/tests/test_serde.rs b/tests/test_serde.rs
index 18b1356..36b87f2 100644
--- a/tests/test_serde.rs
+++ b/tests/test_serde.rs
@@ -1,7 +1,7 @@
#![cfg(feature = "serde")]
#![deny(warnings, rust_2018_idioms)]
-use serde_test::{Token, assert_tokens};
+use serde_test::{assert_tokens, Token};
#[test]
fn test_ser_de_empty() {