diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 00:29:26 +0200 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 00:29:26 +0200 |
commit | b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994 (patch) | |
tree | 28224f6af3253f0ca9ee6b17980e4dc24b907cba | |
parent | e1a8aede05d3217882cf2de426f0a87a659e4308 (diff) | |
download | luasystem-b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994.zip |
add final (failing for now) tests, to be fixed
-rw-r--r-- | spec/04-term_spec.lua | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index 3dc4660..c5b91e6 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua @@ -174,18 +174,97 @@ describe("Terminal:", function() - pending("tcgetattr()", function() + describe("tcgetattr()", function() - pending("sets the consoleflags, if called with flags", function() + pending("gets the terminal flags", function() + end) + + + win_it("gets the terminal flags, always 0", function() + local flags, err = system.tcgetattr(io.stdin) + assert.is_nil(err) + assert.is_table(flags) + assert.equals("bitflags:", tostring(flags.iflag):sub(1,9)) + assert.equals("bitflags:", tostring(flags.oflag):sub(1,9)) + assert.equals("bitflags:", tostring(flags.lflag):sub(1,9)) + assert.equals("bitflags:", tostring(flags.cflag):sub(1,9)) + assert.equals(0, flags.iflag:value()) + assert.equals(0, flags.oflag:value()) + assert.equals(0, flags.lflag:value()) + assert.equals(0, flags.cflag:value()) + assert.same({}, flags.cc) + end) + + + it("returns an error if called with an invalid argument", function() + assert.has.error(function() + system.tcgetattr("invalid") + end, "bad argument #1 to 'tcgetattr' (FILE* expected, got string)") end) end) - pending("tcsetattr()", function() + describe("tcsetattr()", function() + + nix_it("sets the terminal flags, if called with flags", function() + assert.equal(true, false) + end) + + + win_it("sets the terminal flags, if called with flags, always succeeds", function() + local success, err = system.tcsetattr(io.stdin, system.TCSANOW, system.tcgetattr(io.stdin)) + assert.is_nil(err) + assert.is_true(success) + end) + + + it("returns an error if called with an invalid first argument", function() + assert.has.error(function() + system.tcsetattr("invalid") + end, "bad argument #1 to 'tcsetattr' (FILE* expected, got string)") + end) + + + it("returns an error if called with an invalid second argument", function() + assert.has.error(function() + system.tcsetattr(io.stdin, "invalid") + end, "bad argument #2 to 'tcsetattr' (number expected, got string)") + end) + + + it("returns an error if called with an invalid third argument", function() + assert.has.error(function() + system.tcsetattr(io.stdin, system.TCSANOW, "invalid") + end, "bad argument #3 to 'tcsetattr' (table expected, got string)") + end) + + + it("returns an error if iflag is not a bitflags object", function() + local flags = assert(system.tcgetattr(io.stdin)) + flags.iflag = 0 + assert.has.error(function() + system.tcsetattr(io.stdin, system.TCSANOW, flags) + end, "bad argument #3 to 'tcsetattr' (table expected, got number)") + end) + + + it("returns an error if oflag is not a bitflags object", function() + local flags = assert(system.tcgetattr(io.stdin)) + flags.oflag = 0 + assert.has.error(function() + system.tcsetattr(io.stdin, system.TCSANOW, flags) + end, "bad argument #3 to 'tcsetattr' (table expected, got number)") + end) + - pending("sets the consoleflags, if called with flags", function() + it("returns an error if lflag is not a bitflags object", function() + local flags = assert(system.tcgetattr(io.stdin)) + flags.lflag = 0 + assert.has.error(function() + system.tcsetattr(io.stdin, system.TCSANOW, flags) + end, "bad argument #3 to 'tcsetattr' (table expected, got number)") end) end) @@ -314,12 +393,20 @@ describe("Terminal:", function() assert.is_boolean(nb) end) + win_it("gets the non-blocking flag, always false", function() local nb, err = system.getnonblock(io.stdin) assert.is_nil(err) assert.is_false(nb) end) + + it("returns an error if called with an invalid argument", function() + assert.has.error(function() + system.getnonblock("invalid") + end, "bad argument #1 to 'getnonblock' (FILE* expected, got string)") + end) + end) |