From 7c1ab71f71087d88aade79925ae68a447397422f Mon Sep 17 00:00:00 2001 From: William Venner Date: Thu, 3 Aug 2023 09:52:57 +0100 Subject: [PATCH] Add assertion to test `skip_until` return value The extra `\0` in this commit is needed because the assertion on line 49 will fail otherwise (as `skip_until` stops reading on EOF and therefore does not read a trailing `\0`, returning 6 read bytes rather than the expected 7) --- library/std/src/io/tests.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs index 9a9a790d77d9..4c5f86fe4316 100644 --- a/library/std/src/io/tests.rs +++ b/library/std/src/io/tests.rs @@ -27,7 +27,7 @@ fn read_until() { #[test] fn skip_until() { - let bytes: &[u8] = b"read\0ignore\0read\0ignore\0read\0ignore"; + let bytes: &[u8] = b"read\0ignore\0read\0ignore\0read\0ignore\0"; let mut reader = BufReader::new(bytes); // read from the bytes, alternating between @@ -41,10 +41,12 @@ fn skip_until() { break; } else { assert_eq!(out, b"read\0"); + assert_eq!(read, b"read\0".len()); } // skip past `ignore\0` - reader.skip_until(0).unwrap(); + 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