mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-23 23:46:55 +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:
parent
3299d0e72a
commit
34a2fd039f
@ -177,9 +177,9 @@ public abstract class AbstractHandle {
|
|||||||
/**
|
/**
|
||||||
* Read the remainder of the file.
|
* 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.
|
* @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
|
* @cc.since 1.80pr1
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -200,6 +200,14 @@ describe("The fs library", function()
|
|||||||
handle.close()
|
handle.close()
|
||||||
end)
|
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()
|
it("can read a line of text", function()
|
||||||
local file = create_test_file "some\nfile\r\ncontents\n\n"
|
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)
|
expect(handle.readLine(true)):eq(nil)
|
||||||
handle.close()
|
handle.close()
|
||||||
end)
|
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
|
end
|
||||||
|
|
||||||
describe("reading", function()
|
describe("reading", function()
|
||||||
|
Loading…
Reference in New Issue
Block a user