diff --git a/docs/luneTypes.d.luau b/docs/luneTypes.d.luau index a4ec16e..06dddd6 100644 --- a/docs/luneTypes.d.luau +++ b/docs/luneTypes.d.luau @@ -138,15 +138,15 @@ declare fs: { An error will be thrown in the following situations: - * The current process lacks permissions to read at `from` or `to`. + * The current process lacks permissions to read at `from` or write at `to`. * The new path exists on a different mount point. * Some other I/O error occurred. @param from The path to move from @param to The path to move to - @param overwriteOrOptions Options the target path, such as if should be overwritten if it already exists + @param overwriteOrOptions Options for the target path, such as if should be overwritten if it already exists ]=] - move: (from: string, to: string, overwriteOrOptions: boolean | FsWriteOptions) -> (), + move: (from: string, to: string, overwriteOrOptions: (boolean | FsWriteOptions)?) -> (), } type NetMethod = "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH" diff --git a/packages/lib/src/tests.rs b/packages/lib/src/tests.rs index 56faa18..71f0b9a 100644 --- a/packages/lib/src/tests.rs +++ b/packages/lib/src/tests.rs @@ -43,6 +43,7 @@ macro_rules! create_tests { create_tests! { fs_files: "fs/files", fs_dirs: "fs/dirs", + fs_move: "fs/move", net_request_codes: "net/request/codes", net_request_methods: "net/request/methods", net_request_redirect: "net/request/redirect", diff --git a/tests/fs/move.luau b/tests/fs/move.luau new file mode 100644 index 0000000..21d47ab --- /dev/null +++ b/tests/fs/move.luau @@ -0,0 +1,58 @@ +-- Generate test data & make sure our bin dir exists + +local binary = "" +for _ = 1, 1024 do + binary ..= string.char(math.random(1, 127)) +end + +local json = net.jsonEncode({ + Foo = "Bar", + Hello = "World", + Inner = { Array = { 1, 2, 3 } }, +}, true) + +fs.writeDir("bin") + +-- Write both of our files + +fs.writeFile("bin/move_test_binary", binary) +fs.writeFile("bin/move_test_json.json", json) + +-- Move / rename them to something else, to test we +-- change the prefix in the names from "move" to "moved" + +fs.move("bin/move_test_binary", "bin/moved_test_binary") +fs.move("bin/move_test_json.json", "bin/moved_test_json.json") + +-- Make sure reading the files we just +-- wrote gets us back the original strings + +assert( + fs.readFile("bin/moved_test_binary") == binary, + "Binary file round-trip resulted in different strings" +) + +assert( + fs.readFile("bin/moved_test_json.json") == json, + "JSON file round-trip resulted in different strings" +) + +-- Remove the files and make sure +-- the APIs say they no longer exist + +fs.removeFile("bin/moved_test_binary") +fs.removeFile("bin/moved_test_json.json") + +assert(not fs.isDir("bin/moved_test_binary"), "Binary after removal isDir check failed") +assert(not fs.isFile("bin/moved_test_binary"), "Binary after removal isFile check failed") + +assert(not fs.isDir("bin/moved_test_json.json"), "JSON after removal isDir check failed") +assert(not fs.isFile("bin/moved_test_json.json"), "JSON after removal isFile check failed") + +-- Also make sure files and dirs at the paths before moving do not exist + +assert(not fs.isDir("bin/moved_test_binary"), "Binary file path still existed after moving") +assert(not fs.isFile("bin/moved_test_binary"), "Binary file path still existed after moving") + +assert(not fs.isDir("bin/moved_test_json.json"), "JSON file path still existed after moving") +assert(not fs.isFile("bin/moved_test_json.json"), "JSON file path still existed after moving")