summaryrefslogtreecommitdiffstats
path: root/library/std/src/io/tests.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
commit73e0a5b7696ea019ba35b89f38fc8e7b285d99cb (patch)
tree0d2e175af6f114cb50a675bec0bc76e12e1bceb4 /library/std/src/io/tests.rs
parentAdding upstream version 1.75.0+dfsg1. (diff)
downloadrustc-upstream.tar.xz
rustc-upstream.zip
Adding upstream version 1.76.0+dfsg1.upstream/1.76.0+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/std/src/io/tests.rs')
-rw-r--r--library/std/src/io/tests.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs
index 6d30f5e6c..bda5b721a 100644
--- a/library/std/src/io/tests.rs
+++ b/library/std/src/io/tests.rs
@@ -26,6 +26,36 @@ fn read_until() {
}
#[test]
+fn skip_until() {
+ let bytes: &[u8] = b"read\0ignore\0read\0ignore\0read\0ignore\0";
+ let mut reader = BufReader::new(bytes);
+
+ // read from the bytes, alternating between
+ // consuming `read\0`s and skipping `ignore\0`s
+ loop {
+ // consume `read\0`
+ let mut out = Vec::new();
+ let read = reader.read_until(0, &mut out).unwrap();
+ if read == 0 {
+ // eof
+ break;
+ } else {
+ assert_eq!(out, b"read\0");
+ assert_eq!(read, b"read\0".len());
+ }
+
+ // skip past `ignore\0`
+ let skipped = reader.skip_until(0).unwrap();
+ assert_eq!(skipped, b"ignore\0".len());
+ }
+
+ // ensure we are at the end of the byte slice and that we can skip no further
+ // also ensure skip_until matches the behavior of read_until at EOF
+ let skipped = reader.skip_until(0).unwrap();
+ assert_eq!(skipped, 0);
+}
+
+#[test]
fn split() {
let buf = Cursor::new(&b"12"[..]);
let mut s = buf.split(b'3');