feat: add Directory.list() method to io module for reading directory entries
Implement a new `Directory` class with a static `list(path)` method that returns an array of filenames from the specified directory. The implementation uses a foreign function `list_(path, fiber)` that performs the actual filesystem read via libuv, collects all directory entries into a zero-byte-terminated buffer, and then splits that buffer into individual strings on the Wren side. Includes test cases for normal directory listing, listing a file path (runtime error), listing a nonexistent path (runtime error), and passing a wrong argument type (runtime error). Also bumps `MAX_CLASSES_PER_MODULE` from 3 to 4 to accommodate the new class.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
this is a text file
|
||||
@@ -0,0 +1 @@
|
||||
this is a text file
|
||||
@@ -0,0 +1 @@
|
||||
this is a text file
|
||||
@@ -0,0 +1,8 @@
|
||||
import "io" for Directory
|
||||
|
||||
var entries = Directory.list("test/io/directory/dir")
|
||||
|
||||
// Ignore OS-specific dot files like ".DS_Store".
|
||||
entries = entries.where {|entry| !entry.startsWith(".") }.toList
|
||||
|
||||
System.print(entries) // expect: [a.txt, b.txt, c.txt]
|
||||
@@ -0,0 +1,3 @@
|
||||
import "io" for Directory
|
||||
|
||||
var entries = Directory.list("test/io/directory/dir/a.txt") // expect runtime error: not a directory
|
||||
@@ -0,0 +1,3 @@
|
||||
import "io" for Directory
|
||||
|
||||
Directory.list("nonexistent") // expect runtime error: no such file or directory
|
||||
@@ -0,0 +1,3 @@
|
||||
import "io" for Directory
|
||||
|
||||
Directory.list(123) // expect runtime error: Path must be a string.
|
||||
Reference in New Issue
Block a user