Skip to content

Commit 98a1cac

Browse files
committed
Add tests to cover SEEK_CUR and SEEK_END
1 parent 2f25e4c commit 98a1cac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/run-pass/fs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ fn main() {
4545
let mut contents = Vec::new();
4646
file.read_to_end(&mut contents).unwrap();
4747
assert_eq!(bytes, contents.as_slice());
48+
// Test seeking relative to the end of the file.
49+
file.seek(SeekFrom::End(-1)).unwrap();
50+
let mut contents = Vec::new();
51+
file.read_to_end(&mut contents).unwrap();
52+
assert_eq!(&bytes[bytes.len() - 1..], contents.as_slice());
53+
// Test seeking relative to the current position.
54+
file.seek(SeekFrom::Start(5)).unwrap();
55+
file.seek(SeekFrom::Current(-3)).unwrap();
56+
let mut contents = Vec::new();
57+
file.read_to_end(&mut contents).unwrap();
58+
assert_eq!(&bytes[2..], contents.as_slice());
4859

4960
// Test that metadata of an absolute path is correct.
5061
test_metadata(bytes, &path).unwrap();

0 commit comments

Comments
 (0)