diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-22 21:37:27 +0200 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-22 21:37:27 +0200 |
commit | 2746189f0a504d5929f8aa69edcc116dbbeff105 (patch) | |
tree | 2176dde5a3b2a439eef175921c61fc1ec4b1be22 /spec | |
parent | b1e250a00406f5268a773f7923bb14708567ce9f (diff) | |
download | luasystem-2746189f0a504d5929f8aa69edcc116dbbeff105.zip |
add tests for termbackup & termrestore
Diffstat (limited to 'spec')
-rw-r--r-- | spec/04-term_spec.lua | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index ba58fde..eb975b5 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua @@ -392,13 +392,45 @@ describe("Terminal:", function() - pending("termbackup()", function() + describe("termbackup() & termrestore()", function() - end) + -- this is all Lua code, so testing one platform should be good enough + win_it("creates and restores a backup", function() + local backup = system.termbackup() + + local old_cp = assert(system.getconsoleoutputcp()) + finally(function() + system.setconsoleoutputcp(old_cp) -- ensure we restore the original one + end) + + -- get the console page... + local new_cp + if old_cp ~= 65001 then + new_cp = 65001 -- set to UTF8 + else + new_cp = 850 -- another common one + end + -- change the console page... + local success, err = system.setconsoleoutputcp(new_cp) + assert.is_nil(err) + assert.is_true(success) + -- ... and check it + local updated_cp = assert(system.getconsoleoutputcp()) + assert.equals(new_cp, updated_cp) + + -- restore the console page + system.termrestore(backup) + local restored_cp = assert(system.getconsoleoutputcp()) + assert.equals(old_cp, restored_cp) + end) - pending("termrestore()", function() + it("termrestore() fails on bad input", function() + assert.has.error(function() + system.termrestore("invalid") + end, "arg #1 to termrestore, expected backup table, got string") + end) end) |