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:
parent
4f60a0b3bd
commit
5b09e721d3
1 changed files with 33 additions and 0 deletions
33
std/wasi/testdata/std_fs_file_seek.rs
vendored
Normal file
33
std/wasi/testdata/std_fs_file_seek.rs
vendored
Normal 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);
|
||||
}
|
Loading…
Add table
Reference in a new issue