File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -918,4 +918,40 @@ mod tests {
918918 assert_eq ! ( format!( "{}" , expect) , format!( "{}" , actual) ) ;
919919 } )
920920 }
921+
922+ #[ test]
923+ fn file_eof_is_not_permanent ( ) -> crate :: io:: Result < ( ) > {
924+ let tempdir = tempfile:: Builder :: new ( )
925+ . prefix ( "async-std-file-eof-test" )
926+ . tempdir ( ) ?;
927+ let path = tempdir. path ( ) . join ( "testfile" ) ;
928+
929+ crate :: task:: block_on ( async {
930+ let mut file_w = File :: create ( & path) . await ?;
931+ let mut file_r = File :: open ( & path) . await ?;
932+
933+ file_w. write_all ( b"data" ) . await ?;
934+ file_w. flush ( ) . await ?;
935+
936+ let mut buf = [ 0u8 ; 4 ] ;
937+ let mut len = file_r. read ( & mut buf) . await ?;
938+ assert_eq ! ( len, 4 ) ;
939+ assert_eq ! ( & buf, b"data" ) ;
940+
941+ len = file_r. read ( & mut buf) . await ?;
942+ assert_eq ! ( len, 0 ) ;
943+
944+ file_w. write_all ( b"more" ) . await ?;
945+ file_w. flush ( ) . await ?;
946+
947+ len = file_r. read ( & mut buf) . await ?;
948+ assert_eq ! ( len, 4 ) ;
949+ assert_eq ! ( & buf, b"more" ) ;
950+
951+ len = file_r. read ( & mut buf) . await ?;
952+ assert_eq ! ( len, 0 ) ;
953+
954+ Ok ( ( ) )
955+ } )
956+ }
921957}
You can’t perform that action at this time.
0 commit comments