Skip to content

Commit

Permalink
add setconsoleflags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 20, 2024
1 parent 06c186d commit 52367be
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions spec/04-term_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ describe("Terminal:", function()
describe("getconsoleflags()", function()

win_it("returns the consoleflags #manual", function()
local flags, err = system.getconsoleflags(io.stdin)
local flags, err = system.getconsoleflags(io.stdout)
assert.is_nil(err)
assert.is_userdata(flags)
assert.equals("bitflags:", tostring(flags):sub(1,9))
end)


nix_it("returns the consoleflags, as value 0", function()
local flags, err = system.getconsoleflags(io.stdin)
nix_it("returns the consoleflags, always value 0", function()
local flags, err = system.getconsoleflags(io.stdout)
assert.is_nil(err)
assert.is_userdata(flags)
assert.equals("bitflags:", tostring(flags):sub(1,9))
Expand All @@ -135,9 +135,39 @@ describe("Terminal:", function()



pending("setconsoleflags()", function()
describe("setconsoleflags()", function()

pending("sets the consoleflags, if called with flags", function()
win_it("sets the consoleflags #manual", function()
local old_flags = assert(system.getconsoleflags(io.stdout))
finally(function()
system.setconsoleflags(io.stdout, old_flags)
end)

local new_flags
if old_flags:has_all_of(system.COF_VIRTUAL_TERMINAL_PROCESSING) then
new_flags = old_flags - system.COF_VIRTUAL_TERMINAL_PROCESSING
else
new_flags = old_flags + system.COF_VIRTUAL_TERMINAL_PROCESSING
end

local success, err = system.setconsoleflags(io.stdout, new_flags)
assert.is_nil(err)
assert.is_true(success)

local updated_flags = assert(system.getconsoleflags(io.stdout))
assert.equals(new_flags:value(), updated_flags:value())
end)


nix_it("sets the consoleflags, always succeeds", function()
assert(system.setconsoleflags(io.stdout, system.getconsoleflags(io.stdout)))
end)


it("returns an error if called with an invalid argument", function()
assert.has.error(function()
system.setconsoleflags("invalid")
end, "bad argument #1 to 'setconsoleflags' (FILE* expected, got string)")
end)

end)
Expand Down

0 comments on commit 52367be

Please sign in to comment.