vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

pipe.lua

(2127B)


      1 local file = vis.win.file
      2 
      3 describe("vis.pipe", function()
      4 
      5 	local FULLSCREEN = true
      6 
      7 	it("vis.pipe no input", function()
      8 		vis:pipe("cat > f")
      9 		local f = io.open("f", "r")
     10 		assert.truthy(f)
     11 		assert.are.equal("", f:read("*a"))
     12 		f:close()
     13 		os.remove("f")
     14 	end)
     15 
     16 	it("vis.pipe no input fullscreen", function()
     17 		vis:pipe("cat > f", FULLSCREEN)
     18 		local f = io.open("f", "r")
     19 		assert.truthy(f)
     20 		assert.are.equal("", f:read("*a"))
     21 		f:close()
     22 		os.remove("f")
     23 	end)
     24 
     25 	it("vis.pipe buffer", function()
     26 		vis:pipe("foo", "cat > f")
     27 		local f = io.open("f", "r")
     28 		assert.truthy(f)
     29 		assert.are.equal(f:read("*a"), "foo")
     30 		f:close()
     31 		os.remove("f")
     32 	end)
     33 
     34 	it("vis.pipe buffer fullscreen", function()
     35 		vis:pipe("foo", "cat > f", FULLSCREEN)
     36 		local f = io.open("f", "r")
     37 		assert.truthy(f)
     38 		assert.are.equal(f:read("*a"), "foo")
     39 		f:close()
     40 		os.remove("f")
     41 	end)
     42 
     43 	it("vis.pipe range", function()
     44 		vis:pipe(file, {start=0, finish=3}, "cat > f")
     45 		local f = io.open("f", "r")
     46 		assert.truthy(f)
     47 		assert.are.equal(f:read("*a"), "foo")
     48 		f:close()
     49 		os.remove("f")
     50 	end)
     51 
     52 	it("vis.pipe range fullscreen", function()
     53 		vis:pipe(file, {start=0, finish=3}, "cat > f", FULLSCREEN)
     54 		local f = io.open("f", "r")
     55 		assert.truthy(f)
     56 		assert.are.equal(f:read("*a"), "foo")
     57 		f:close()
     58 		os.remove("f")
     59 	end)
     60 
     61 	it("vis.pipe explicit nil text", function()
     62 		assert.has_error(function() vis:pipe(nil, "true") end)
     63 	end)
     64 
     65 	it("vis.pipe explicit nil text fullscreen", function()
     66 		assert.has_error(function() vis:pipe(nil, "true", FULLSCREEN) end)
     67 	end)
     68 
     69 	it("vis.pipe explicit nil file", function()
     70 		assert.has_error(function() vis:pipe(nil, {start=0, finish=0}, "true") end)
     71 	end)
     72 
     73 	it("vis.pipe explicit nil file fullscreen", function()
     74 		assert.has_error(function() vis:pipe(nil, {start=0, finish=0}, "true", FULLSCREEN) end)
     75 	end)
     76 
     77 	it("vis.pipe wrong argument order file, range, cmd", function()
     78 		assert.has_error(function() vis:pipe({start=0, finish=0}, vis.win.file, "true") end)
     79 	end)
     80 
     81 	it("vis.pipe wrong argument order fullscreen, cmd", function()
     82 		assert.has_error(function() vis:pipe(FULLSCREEN, "true") end)
     83 	end)
     84 end)