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 @@ -913,4 +913,40 @@ mod tests {
913
913
assert_eq ! ( format!( "{}" , expect) , format!( "{}" , actual) ) ;
914
914
} )
915
915
}
916
+
917
+ #[ test]
918
+ fn file_eof_is_not_permanent ( ) -> crate :: io:: Result < ( ) > {
919
+ let tempdir = tempfile:: Builder :: new ( )
920
+ . prefix ( "async-std-file-eof-test" )
921
+ . tempdir ( ) ?;
922
+ let path = tempdir. path ( ) . join ( "testfile" ) ;
923
+
924
+ crate :: task:: block_on ( async {
925
+ let mut file_w = File :: create ( & path) . await ?;
926
+ let mut file_r = File :: open ( & path) . await ?;
927
+
928
+ file_w. write_all ( b"data" ) . await ?;
929
+ file_w. flush ( ) . await ?;
930
+
931
+ let mut buf = [ 0u8 ; 4 ] ;
932
+ let mut len = file_r. read ( & mut buf) . await ?;
933
+ assert_eq ! ( len, 4 ) ;
934
+ assert_eq ! ( & buf, b"data" ) ;
935
+
936
+ len = file_r. read ( & mut buf) . await ?;
937
+ assert_eq ! ( len, 0 ) ;
938
+
939
+ file_w. write_all ( b"more" ) . await ?;
940
+ file_w. flush ( ) . await ?;
941
+
942
+ len = file_r. read ( & mut buf) . await ?;
943
+ assert_eq ! ( len, 4 ) ;
944
+ assert_eq ! ( & buf, b"more" ) ;
945
+
946
+ len = file_r. read ( & mut buf) . await ?;
947
+ assert_eq ! ( len, 0 ) ;
948
+
949
+ Ok ( ( ) )
950
+ } )
951
+ }
916
952
}
You can’t perform that action at this time.
0 commit comments