From ff3ae4521ba7fffb36e4038cbc89144a59681d84 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Tue, 14 May 2024 15:48:42 +0330 Subject: [PATCH] add a test to wasi-fyi tess --- tests/wasi-fyi/fs_seek_append_mode.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/wasi-fyi/fs_seek_append_mode.rs diff --git a/tests/wasi-fyi/fs_seek_append_mode.rs b/tests/wasi-fyi/fs_seek_append_mode.rs new file mode 100644 index 00000000000..7e1d54321f0 --- /dev/null +++ b/tests/wasi-fyi/fs_seek_append_mode.rs @@ -0,0 +1,24 @@ +use std::fs::OpenOptions; +use std::io::prelude::*; +use std::io::SeekFrom; + +fn main() { + let mut file = OpenOptions::new() + .append(true) + .read(true) + .create(true) + .open("file") + .unwrap(); + + // file offset must be 1 now + write!(file, "{}", "a").unwrap(); + + // rewind should not work on file in append mode + // since the offset must always be at the end of the file + let _ = file.rewind(); + + // file offset must be 2 now + write!(file, "{}", "b").unwrap(); + + assert_eq!(file.seek(SeekFrom::Current(0)).unwrap(), 2); +}