aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 21:37:27 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 21:37:27 +0200
commit2746189f0a504d5929f8aa69edcc116dbbeff105 (patch)
tree2176dde5a3b2a439eef175921c61fc1ec4b1be22 /spec
parentb1e250a00406f5268a773f7923bb14708567ce9f (diff)
downloadluasystem-2746189f0a504d5929f8aa69edcc116dbbeff105.tar.gz
luasystem-2746189f0a504d5929f8aa69edcc116dbbeff105.tar.bz2
luasystem-2746189f0a504d5929f8aa69edcc116dbbeff105.zip
add tests for termbackup & termrestore
Diffstat (limited to 'spec')
-rw-r--r--spec/04-term_spec.lua38
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()
392 392
393 393
394 394
395 pending("termbackup()", function() 395 describe("termbackup() & termrestore()", function()
396 396
397 end) 397 -- this is all Lua code, so testing one platform should be good enough
398 win_it("creates and restores a backup", function()
399 local backup = system.termbackup()
400
401 local old_cp = assert(system.getconsoleoutputcp())
402 finally(function()
403 system.setconsoleoutputcp(old_cp) -- ensure we restore the original one
404 end)
405
406 -- get the console page...
407 local new_cp
408 if old_cp ~= 65001 then
409 new_cp = 65001 -- set to UTF8
410 else
411 new_cp = 850 -- another common one
412 end
398 413
414 -- change the console page...
415 local success, err = system.setconsoleoutputcp(new_cp)
416 assert.is_nil(err)
417 assert.is_true(success)
418 -- ... and check it
419 local updated_cp = assert(system.getconsoleoutputcp())
420 assert.equals(new_cp, updated_cp)
421
422 -- restore the console page
423 system.termrestore(backup)
424 local restored_cp = assert(system.getconsoleoutputcp())
425 assert.equals(old_cp, restored_cp)
426 end)
399 427
400 428
401 pending("termrestore()", function() 429 it("termrestore() fails on bad input", function()
430 assert.has.error(function()
431 system.termrestore("invalid")
432 end, "arg #1 to termrestore, expected backup table, got string")
433 end)
402 434
403 end) 435 end)
404 436