summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 20:07:42 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 20:07:42 +0200
commit14c0f9e3b2587411d4261cb7771bdce6931b31d5 (patch)
tree3c7388e494f36b0af84a723fd2acd921eaa3616a
parenteb310864f70efc4bb46da73f2ee2b9c0d2940c1e (diff)
downloadluasystem-14c0f9e3b2587411d4261cb7771bdce6931b31d5.zip
add tests for termwrap
-rw-r--r--spec/04-term_spec.lua60
1 files changed, 59 insertions, 1 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index b6e0daf..ba58fde 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -404,7 +404,65 @@ describe("Terminal:", function()
- pending("termwrap()", function()
+ describe("termwrap()", function()
+
+ local old_backup
+ local old_restore
+ local result
+
+ setup(function()
+ old_backup = system.termbackup
+ old_restore = system.termrestore
+ system.termbackup = function()
+ table.insert(result,"backup")
+ end
+
+ system.termrestore = function()
+ table.insert(result,"restore")
+ end
+ end)
+
+
+ before_each(function()
+ result = {}
+ end)
+
+
+ teardown(function()
+ system.termbackup = old_backup
+ system.termrestore = old_restore
+ end)
+
+
+
+ it("calls both backup and restore", function()
+ system.termwrap(function()
+ table.insert(result,"wrapped")
+ end)()
+
+ assert.are.same({"backup", "wrapped", "restore"}, result)
+ end)
+
+
+ it("passes all args", function()
+ system.termwrap(function(...)
+ table.insert(result,{...})
+ end)(1, 2, 3)
+
+ assert.are.same({"backup", {1,2,3}, "restore"}, result)
+ end)
+
+
+ it("returns all results", function()
+ local a, b, c = system.termwrap(function(...)
+ return 1, nil, 3 -- ensure nil is passed as well
+ end)()
+
+ assert.are.same({"backup", "restore"}, result)
+ assert.equals(1, a)
+ assert.is_nil(b)
+ assert.equals(3, c)
+ end)
end)