From 359e3751ea5b7e7fca685a61bd08a4a6c86f845c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 10 Sep 2024 09:55:25 +0200 Subject: [PATCH] lua: add tests for different vis.pipe argument variants --- test/lua/pipe.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/lua/pipe.lua b/test/lua/pipe.lua index 7b6c80877..9dfb670bc 100644 --- a/test/lua/pipe.lua +++ b/test/lua/pipe.lua @@ -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") @@ -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") @@ -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)