1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

test(std/wasi) add std::fs::File seek test (#6648)

This commit is contained in:
Casper Beyer 2020-07-06 09:36:45 +08:00 committed by GitHub
parent 4f60a0b3bd
commit 5b09e721d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

33
std/wasi/testdata/std_fs_file_seek.rs vendored Normal file
View file

@ -0,0 +1,33 @@
// { "preopens": { "/fixture": "fixture" } }
use std::io::Seek;
fn main() {
let mut file = std::fs::File::open("/fixture/file").unwrap();
assert_eq!(file.seek(std::io::SeekFrom::Current(0)).unwrap(), 0);
assert_eq!(file.seek(std::io::SeekFrom::Start(1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Start(2)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Start(3)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Start(4)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Start(5)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 0);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::End(0)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::End(-1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::End(-2)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::End(-3)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::End(-4)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::End(-5)).unwrap(), 0);
}