2023-05-14 21:16:58 +01:00
|
|
|
local fs = require("@lune/fs")
|
2023-07-20 19:06:42 +01:00
|
|
|
local utils = require("./utils")
|
2023-05-14 21:16:58 +01:00
|
|
|
|
2023-07-20 19:06:42 +01:00
|
|
|
-- Make sure our bin dir exists
|
2023-02-23 09:20:57 +00:00
|
|
|
|
|
|
|
fs.writeDir("bin")
|
|
|
|
|
|
|
|
-- Write both of our files
|
|
|
|
|
2023-07-20 19:06:42 +01:00
|
|
|
fs.writeFile("bin/move_test_binary", utils.binaryBlob)
|
|
|
|
fs.writeFile("bin/move_test_json.json", utils.jsonBlob)
|
2023-02-23 09:20:57 +00:00
|
|
|
|
|
|
|
-- 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(
|
2024-04-20 15:44:19 +01:00
|
|
|
fs.readFile("bin/moved_test_binary") == buffer.tostring(utils.binaryBlob),
|
2023-02-23 09:20:57 +00:00
|
|
|
"Binary file round-trip resulted in different strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert(
|
2023-07-20 19:06:42 +01:00
|
|
|
fs.readFile("bin/moved_test_json.json") == utils.jsonBlob,
|
2023-02-23 09:20:57 +00:00
|
|
|
"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")
|