summaryrefslogtreecommitdiffstats
path: root/third_party/rust/bytes-0.4.12/tests/test_buf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/bytes-0.4.12/tests/test_buf.rs')
-rw-r--r--third_party/rust/bytes-0.4.12/tests/test_buf.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/third_party/rust/bytes-0.4.12/tests/test_buf.rs b/third_party/rust/bytes-0.4.12/tests/test_buf.rs
new file mode 100644
index 0000000000..f25c25f2b5
--- /dev/null
+++ b/third_party/rust/bytes-0.4.12/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[..]));
+}