@@ -31,6 +31,9 @@ main! = |_args|
3131 # Test file rename
3232 test_file_rename!({})?
3333
34+ # Test file exists
35+ test_file_exists!({})?
36+
3437 # Clean up test files
3538 cleanup_test_files!({})?
3639
@@ -206,6 +209,33 @@ test_file_rename! = |{}|
206209
207210 Ok ({})
208211
212+ test_file_exists ! : {} => Result {} _
213+ test_file_exists ! = |{}|
214+ Stdout . line !("\nTesting File . exists !:")?
215+
216+ # Test that a file that exists returns true
217+ filename = " test_exists.txt"
218+ File . write_utf8 !("", filename)?
219+
220+ test_file_exists = File . exists !(filename ) ? |err| FileExistsCheckFailed (err)
221+
222+ if test_file_exists then
223+ Stdout . line !("✓ File . exists ! returns true for a file that exists" )?
224+ else
225+ Stderr.line!(" ✗ File . exists ! returned false for a file that exists" )?
226+
227+ # Test that a file that does not exist returns false
228+ File.delete!(filename)?
229+
230+ test_file_exists_after_delete = File.exists!(filename) ? |err| FileExistsCheckAfterDeleteFailed(err)
231+
232+ if test_file_exists_after_delete then
233+ Stderr.line!(" ✗ File . exists ! returned true for a file that does not exist" )?
234+ else
235+ Stdout.line!(" ✓ File . exists ! returns false for a file that does not exist" )?
236+
237+ Ok({})
238+
209239cleanup_test_files! : {} => Result {} _
210240cleanup_test_files! = |{}|
211241 Stdout.line!(" \nCleaning up test files..." )?
@@ -217,7 +247,7 @@ cleanup_test_files! = |{}|
217247 " test_multiline. txt " ,
218248 " test_original_file. txt " ,
219249 " test_link_to_original. txt " ,
220- " test_rename_new. txt "
250+ " test_rename_new. txt " ,
221251 ]
222252
223253 List.for_each_try!(test_files, |filename| File.delete!(filename)) ? |err| FileDeletionFailed(err)
0 commit comments