mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
test(std/wasi): add std file read and write tests (#6671)
This commit is contained in:
parent
158ae0bfe9
commit
9e0bc25142
2 changed files with 25 additions and 0 deletions
16
std/wasi/testdata/std_fs_file_read.rs
vendored
Normal file
16
std/wasi/testdata/std_fs_file_read.rs
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// { "preopens": { "/fixture": "fixture" } }
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
fn main() {
|
||||
let mut file = std::fs::File::open("/fixture/file").unwrap();
|
||||
let mut buffer = [0; 2];
|
||||
|
||||
assert_eq!(file.read(&mut buffer).unwrap(), 2);
|
||||
assert_eq!(&buffer, b"fi");
|
||||
|
||||
assert_eq!(file.read(&mut buffer).unwrap(), 2);
|
||||
assert_eq!(&buffer, b"le");
|
||||
|
||||
assert_eq!(file.read(&mut buffer).unwrap(), 1);
|
||||
}
|
9
std/wasi/testdata/std_fs_file_write.rs
vendored
Normal file
9
std/wasi/testdata/std_fs_file_write.rs
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let mut file = std::fs::File::create("/scratch/file").unwrap();
|
||||
assert_eq!(file.write(b"fi").unwrap(), 2);
|
||||
assert_eq!(file.write(b"le").unwrap(), 2);
|
||||
}
|
Loading…
Add table
Reference in a new issue