mirror of
https://github.com/lune-org/lune.git
synced 2025-04-19 19:34:02 +01:00
feat(types + tests): updated types and tests for @lune/fs
This commit is contained in:
parent
caecf9edd1
commit
a1b11345a1
2 changed files with 20 additions and 7 deletions
|
@ -9,22 +9,35 @@ local utils = require("./utils")
|
||||||
fs.writeDir(TEMP_DIR_PATH)
|
fs.writeDir(TEMP_DIR_PATH)
|
||||||
fs.writeDir(TEMP_ROOT_PATH)
|
fs.writeDir(TEMP_ROOT_PATH)
|
||||||
|
|
||||||
-- Write both of our files
|
-- Write both of our files with string and buffer contents
|
||||||
|
|
||||||
fs.writeFile(TEMP_ROOT_PATH .. "/test_binary", utils.binaryBlob)
|
fs.writeFile(TEMP_ROOT_PATH .. "/test_binary", utils.binaryBlob)
|
||||||
fs.writeFile(TEMP_ROOT_PATH .. "/test_json.json", utils.jsonBlob)
|
fs.writeFile(TEMP_ROOT_PATH .. "/test_json.json", utils.jsonBlob)
|
||||||
|
|
||||||
|
fs.writeFile(TEMP_ROOT_PATH .. "/test_binary_buf", buffer.fromstring(utils.binaryBlob))
|
||||||
|
fs.writeFile(TEMP_ROOT_PATH .. "/test_json_buf.json", buffer.fromstring(utils.jsonBlob))
|
||||||
|
|
||||||
-- Make sure reading the file we just
|
-- Make sure reading the file we just
|
||||||
-- wrote gets us back the original strings
|
-- wrote gets us back the original strings
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
fs.readFile(TEMP_ROOT_PATH .. "/test_binary") == utils.binaryBlob,
|
buffer.tostring(fs.readFile(TEMP_ROOT_PATH .. "/test_binary")) == utils.binaryBlob,
|
||||||
"Binary file round-trip resulted in different strings"
|
"(String) Binary file round-trip resulted in different strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
fs.readFile(TEMP_ROOT_PATH .. "/test_json.json") == utils.jsonBlob,
|
buffer.tostring(fs.readFile(TEMP_ROOT_PATH .. "/test_json.json")) == utils.jsonBlob,
|
||||||
"JSON file round-trip resulted in different strings"
|
"(String) JSON file round-trip resulted in different strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
buffer.tostring(fs.readFile(TEMP_ROOT_PATH .. "/test_binary_buf")) == utils.binaryBlob,
|
||||||
|
"(Buffer) Binary file round-trip resulted in different strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
buffer.tostring(fs.readFile(TEMP_ROOT_PATH .. "/test_json_buf.json")) == utils.jsonBlob,
|
||||||
|
"(Buffer) JSON file round-trip resulted in different strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Make sure file checks succeed but dir checks fail
|
-- Make sure file checks succeed but dir checks fail
|
||||||
|
|
|
@ -107,7 +107,7 @@ local fs = {}
|
||||||
@param path The path to the file to read
|
@param path The path to the file to read
|
||||||
@return The contents of the file
|
@return The contents of the file
|
||||||
]=]
|
]=]
|
||||||
function fs.readFile(path: string): string
|
function fs.readFile(path: string): buffer
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ end
|
||||||
@param path The path of the file
|
@param path The path of the file
|
||||||
@param contents The contents of the file
|
@param contents The contents of the file
|
||||||
]=]
|
]=]
|
||||||
function fs.writeFile(path: string, contents: string) end
|
function fs.writeFile(path: string, contents: buffer | string) end
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
@within FS
|
@within FS
|
||||||
|
|
Loading…
Add table
Reference in a new issue