From c8694ee0f0fb0540bf0d4e7a25f65924eda02caf Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 8 Sep 2024 19:03:54 +0200 Subject: lua: add tests for the different vis.pipe argument variants --- test/lua/pipe.in | 1 + test/lua/pipe.lua | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 test/lua/pipe.in create mode 100644 test/lua/pipe.lua diff --git a/test/lua/pipe.in b/test/lua/pipe.in new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/test/lua/pipe.in @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/test/lua/pipe.lua b/test/lua/pipe.lua new file mode 100644 index 0000000..9dfb670 --- /dev/null +++ b/test/lua/pipe.lua @@ -0,0 +1,86 @@ +require 'busted.runner'() + +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") + assert.truthy(f) + assert.are.equal(f:read("*a"), "foo") + f:close() + 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") + assert.truthy(f) + assert.are.equal(f:read("*a"), "foo") + 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) -- cgit v1.2.3