]> git.lizzy.rs Git - rust.git/commitdiff
Add tests to cover SEEK_CUR and SEEK_END
authorDavid Cook <divergentdave@gmail.com>
Thu, 6 Feb 2020 23:50:33 +0000 (17:50 -0600)
committerDavid Cook <divergentdave@gmail.com>
Thu, 6 Feb 2020 23:50:33 +0000 (17:50 -0600)
tests/run-pass/fs.rs

index 4da67369aef8425fc2db976e127e8d1ee9d52a31..73e6f37453fa5c73a2148f1dced97ab5b95e393a 100644 (file)
@@ -45,6 +45,17 @@ fn main() {
     let mut contents = Vec::new();
     file.read_to_end(&mut contents).unwrap();
     assert_eq!(bytes, contents.as_slice());
+    // Test seeking relative to the end of the file.
+    file.seek(SeekFrom::End(-1)).unwrap();
+    let mut contents = Vec::new();
+    file.read_to_end(&mut contents).unwrap();
+    assert_eq!(&bytes[bytes.len() - 1..], contents.as_slice());
+    // Test seeking relative to the current position.
+    file.seek(SeekFrom::Start(5)).unwrap();
+    file.seek(SeekFrom::Current(-3)).unwrap();
+    let mut contents = Vec::new();
+    file.read_to_end(&mut contents).unwrap();
+    assert_eq!(&bytes[2..], contents.as_slice());
 
     // Test that metadata of an absolute path is correct.
     test_metadata(bytes, &path).unwrap();