1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-23 15:36:54 +00:00

Clarify behaviour of readAll at the end of a file

This should return an empty string, to match PUC Lua.
This commit is contained in:
Jonathan Coates 2024-08-18 11:03:17 +01:00
parent 3299d0e72a
commit 34a2fd039f
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 20 additions and 2 deletions

View File

@ -177,9 +177,9 @@ public abstract class AbstractHandle {
/**
* Read the remainder of the file.
*
* @return The file, or {@code null} if at the end of it.
* @return The remaining contents of the file, or {@code null} in the event of an error.
* @throws LuaException If the file has been closed.
* @cc.treturn string|nil The remaining contents of the file, or {@code nil} if we are at the end.
* @cc.treturn string|nil The remaining contents of the file, or {@code nil} in the event of an error.
* @cc.since 1.80pr1
*/
@Nullable

View File

@ -200,6 +200,14 @@ describe("The fs library", function()
handle.close()
end)
it("reading an empty file returns nil", function()
local file = create_test_file ""
local handle = fs.open(file, mode)
expect(handle.read()):eq(nil)
handle.close()
end)
it("can read a line of text", function()
local file = create_test_file "some\nfile\r\ncontents\n\n"
@ -223,6 +231,16 @@ describe("The fs library", function()
expect(handle.readLine(true)):eq(nil)
handle.close()
end)
it("readAll always returns a string", function()
local contents = "some\nfile\ncontents"
local file = create_test_file "some\nfile\ncontents"
local handle = fs.open(file, mode)
expect(handle.readAll()):eq(contents)
expect(handle.readAll()):eq("")
handle.close()
end)
end
describe("reading", function()