summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs <thijs@thijsschreijer.nl>2024-05-20 23:05:08 +0200
committerThijs <thijs@thijsschreijer.nl>2024-05-20 23:08:09 +0200
commit52367bec91db06afaad8ed9c173e9fe0c50ec864 (patch)
tree0e21286aaa68e2d767b1b9d3885badc2b27fa3c5
parent06c186da3c9108c9d0378e25a18bc6f605d43644 (diff)
downloadluasystem-52367bec91db06afaad8ed9c173e9fe0c50ec864.zip
add setconsoleflags tests
-rw-r--r--spec/04-term_spec.lua40
1 files changed, 35 insertions, 5 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 487a0ce..77d2ce3 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -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))
@@ -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)