Skip to content

Commit

Permalink
lua: add tests for different vis.pipe argument variants
Browse files Browse the repository at this point in the history
  • Loading branch information
fischerling committed Sep 10, 2024
1 parent 346c5ef commit 359e375
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/lua/pipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ local file = vis.win.file

describe("vis.pipe", function()

local FULLSCREEN = true

it("vis.pipe no input", function()
vis:pipe("cat > f")
local f = io.open("f", "r")
assert.truthy(f)
assert.are.equal("", f:read("*a"))
f:close()
os.remove("f")
end)

it("vis.pipe no input fullscreen", function()
vis:pipe("cat > f", FULLSCREEN)
local f = io.open("f", "r")
assert.truthy(f)
assert.are.equal("", f:read("*a"))
f:close()
os.remove("f")
end)

it("vis.pipe buffer", function()
vis:pipe("foo", "cat > f")
local f = io.open("f", "r")
Expand All @@ -13,6 +33,15 @@ describe("vis.pipe", function()
os.remove("f")
end)

it("vis.pipe buffer fullscreen", function()
vis:pipe("foo", "cat > f", FULLSCREEN)
local f = io.open("f", "r")
assert.truthy(f)
assert.are.equal(f:read("*a"), "foo")
f:close()
os.remove("f")
end)

it("vis.pipe range", function()
vis:pipe(file, {start=0, finish=3}, "cat > f")
local f = io.open("f", "r")
Expand All @@ -21,4 +50,37 @@ describe("vis.pipe", function()
f:close()
os.remove("f")
end)

it("vis.pipe range fullscreen", function()
vis:pipe(file, {start=0, finish=3}, "cat > f", FULLSCREEN)
local f = io.open("f", "r")
assert.truthy(f)
assert.are.equal(f:read("*a"), "foo")
f:close()
os.remove("f")
end)

it("vis.pipe explicit nil text", function()
assert.has_error(function() vis:pipe(nil, "true") end)
end)

it("vis.pipe explicit nil text fullscreen", function()
assert.has_error(function() vis:pipe(nil, "true", FULLSCREEN) end)
end)

it("vis.pipe explicit nil file", function()
assert.has_error(function() vis:pipe(nil, {start=0, finish=0}, "true") end)
end)

it("vis.pipe explicit nil file fullscreen", function()
assert.has_error(function() vis:pipe(nil, {start=0, finish=0}, "true", FULLSCREEN) end)
end)

it("vis.pipe wrong argument order file, range, cmd", function()
assert.has_error(function() vis:pipe({start=0, finish=0}, vis.win.file, "true") end)
end)

it("vis.pipe wrong argument order fullscreen, cmd", function()
assert.has_error(function() vis:pipe(FULLSCREEN, "true") end)
end)
end)

0 comments on commit 359e375

Please sign in to comment.