Skip to content

Commit

Permalink
add a test to wasi-fyi tess
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed May 14, 2024
1 parent d2e72c0 commit ff3ae45
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/wasi-fyi/fs_seek_append_mode.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit ff3ae45

Please sign in to comment.