Implement FLUSH-FILE
[pforth] / fth / t_file.fth
index 2817f05..328ae7f 100644 (file)
@@ -73,14 +73,11 @@ true value verbose
 : s= compare 0= ;
 : $" state IF postpone s" else ['] s" execute THEN ; immediate
 
 : s= compare 0= ;
 : $" state IF postpone s" else ['] s" execute THEN ; immediate
 
-
-\ FIXME: stubs for missing definition
-: flush-file drop -1 ;
+\ FIXME: stubs for missing definitions
 : resize-file drop 2drop -1 ;
 : rename-file 2drop 2drop -1 ;
 : file-status 2drop 0 -1 ;
 
 : resize-file drop 2drop -1 ;
 : rename-file 2drop 2drop -1 ;
 : file-status 2drop 0 -1 ;
 
-
 TESTING File Access word set
 
 DECIMAL
 TESTING File Access word set
 
 DECIMAL
@@ -118,6 +115,23 @@ T{ BUF 100 FID1 @ READ-LINE ROT DUP #CHARS ! -> TRUE 0 LINE1 SWAP DROP }T
 T{ BUF #CHARS @ LINE1 S= -> TRUE }T
 T{ FID1 @ CLOSE-FILE -> 0 }T
 
 T{ BUF #CHARS @ LINE1 S= -> TRUE }T
 T{ FID1 @ CLOSE-FILE -> 0 }T
 
+\ Test with buffer shorter than line.
+T{ FN1 R/O OPEN-FILE SWAP FID1 ! -> 0 }T
+T{ FID1 @ FILE-POSITION -> 0. 0 }T
+T{ BUF 0 FID1 @ READ-LINE ROT DUP #CHARS ! -> TRUE 0 0 }T
+T{ BUF 3 FID1 @ READ-LINE ROT DUP #CHARS ! -> TRUE 0 3 }T
+T{ BUF #CHARS @ LINE1 DROP 3 S= -> TRUE }T
+T{ BUF 100 FID1 @ READ-LINE ROT DUP #CHARS ! -> TRUE 0 LINE1 NIP 3 - }T
+T{ BUF #CHARS @ LINE1 3 /STRING S= -> TRUE }T
+T{ FID1 @ CLOSE-FILE -> 0 }T
+
+\ Test with buffer exactly as long as the line.
+T{ FN1 R/O OPEN-FILE SWAP FID1 ! -> 0 }T
+T{ FID1 @ FILE-POSITION -> 0. 0 }T
+T{ BUF LINE1 NIP FID1 @ READ-LINE ROT DUP #CHARS ! -> TRUE 0 LINE1 NIP }T
+T{ BUF #CHARS @ LINE1 S= -> TRUE }T
+T{ FID1 @ CLOSE-FILE -> 0 }T
+
 \ ----------------------------------------------------------------------------
 TESTING S" in interpretation mode (compile mode tested in Core tests)
 
 \ ----------------------------------------------------------------------------
 TESTING S" in interpretation mode (compile mode tested in Core tests)