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 file read and write tests (#6671)

This commit is contained in:
Casper Beyer 2020-07-07 12:49:04 +08:00 committed by GitHub
parent 158ae0bfe9
commit 9e0bc25142
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

16
std/wasi/testdata/std_fs_file_read.rs vendored Normal file
View 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);
}

View 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);
}