feat: add Stat.isFile, Stat.isDirectory, File.exists, and Directory.exists methods

Add four new file system checking functions: Stat.isFile and Stat.isDirectory for querying entry type from a Stat object, and File.exists and Directory.exists static methods that return booleans by attempting to stat the path and checking the appropriate type. Also bump MAX_METHODS_PER_CLASS from 12 to 14 to accommodate the new Stat foreign methods, and clean up unused Scheduler imports in existing stat tests.
This commit is contained in:
Bob Nystrom
2016-02-21 20:23:33 +00:00
parent 7f744565fc
commit 1973934fa2
15 changed files with 149 additions and 28 deletions
+9
View File
@@ -0,0 +1,9 @@
import "io" for Directory
System.print(Directory.exists("test/io/file")) // expect: true
System.print(Directory.exists("nonexistent")) // expect: false
// Files are not directories.
System.print(Directory.exists("test/io/file/file.txt")) // expect: false
// TODO: Symlinks.
@@ -0,0 +1,3 @@
import "io" for Directory
Directory.exists(123) // expect runtime error: Path must be a string.
+9
View File
@@ -0,0 +1,9 @@
import "io" for File
System.print(File.exists("test/io/file/file.txt")) // expect: true
System.print(File.exists("nonexistent")) // expect: false
// Directories are not files.
System.print(File.exists("test/io/file")) // expect: false
// TODO: Symlinks.
+3
View File
@@ -0,0 +1,3 @@
import "io" for File
File.exists(123) // expect runtime error: Path must be a string.
+4
View File
@@ -0,0 +1,4 @@
import "io" for Stat
System.print(Stat.path("test/io/file/file.txt").isDirectory) // expect: false
System.print(Stat.path("test").isDirectory) // expect: true
+4
View File
@@ -0,0 +1,4 @@
import "io" for Stat
System.print(Stat.path("test/io/file/file.txt").isFile) // expect: true
System.print(Stat.path("test").isFile) // expect: false
-1
View File
@@ -1,5 +1,4 @@
import "io" for Stat
import "scheduler" for Scheduler
var stat = Stat.path("test/io/file/file.txt")
-1
View File
@@ -1,5 +1,4 @@
import "io" for Stat
import "scheduler" for Scheduler
var stat = Stat.path("test/io/directory/dir")