aboutsummaryrefslogtreecommitdiff
path: root/test/lua/pipe.lua
blob: 1edd073bbdee6f79d09bdf494452527357f3dbeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)