summaryrefslogtreecommitdiffstats
path: root/third_party/rust/bytes/tests/test_reader.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /third_party/rust/bytes/tests/test_reader.rs
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/bytes/tests/test_reader.rs')
-rw-r--r--third_party/rust/bytes/tests/test_reader.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/rust/bytes/tests/test_reader.rs b/third_party/rust/bytes/tests/test_reader.rs
new file mode 100644
index 0000000000..897aff6455
--- /dev/null
+++ b/third_party/rust/bytes/tests/test_reader.rs
@@ -0,0 +1,29 @@
+#![warn(rust_2018_idioms)]
+#![cfg(feature = "std")]
+
+use std::io::{BufRead, Read};
+
+use bytes::Buf;
+
+#[test]
+fn read() {
+ let buf1 = &b"hello "[..];
+ let buf2 = &b"world"[..];
+ let buf = Buf::chain(buf1, buf2); // Disambiguate with Read::chain
+ let mut buffer = Vec::new();
+ buf.reader().read_to_end(&mut buffer).unwrap();
+ assert_eq!(b"hello world", &buffer[..]);
+}
+
+#[test]
+fn buf_read() {
+ let buf1 = &b"hell"[..];
+ let buf2 = &b"o\nworld"[..];
+ let mut reader = Buf::chain(buf1, buf2).reader();
+ let mut line = String::new();
+ reader.read_line(&mut line).unwrap();
+ assert_eq!("hello\n", &line);
+ line.clear();
+ reader.read_line(&mut line).unwrap();
+ assert_eq!("world", &line);
+}