Skip to content

Commit

Permalink
add tests for termwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 22, 2024
1 parent eb31086 commit 14c0f9e
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion spec/04-term_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 14c0f9e

Please sign in to comment.