test: screen_setup(): Support cols parameter.

This commit is contained in:
Justin M. Keyes
2017-02-22 16:10:10 +01:00
parent 9dbda59715
commit d90e5f5260
2 changed files with 161 additions and 159 deletions

View File

@@ -34,12 +34,15 @@ local function disable_mouse() feed_termcode('[?1002l') end
local default_command = '["'..nvim_dir..'/tty-test'..'"]' local default_command = '["'..nvim_dir..'/tty-test'..'"]'
local function screen_setup(extra_height, command) local function screen_setup(extra_rows, command, cols)
extra_rows = extra_rows and extra_rows or 0
command = command and command or default_command
cols = cols and cols or 50
nvim('command', 'highlight TermCursor cterm=reverse') nvim('command', 'highlight TermCursor cterm=reverse')
nvim('command', 'highlight TermCursorNC ctermbg=11') nvim('command', 'highlight TermCursorNC ctermbg=11')
if not extra_height then extra_height = 0 end
if not command then command = default_command end local screen = Screen.new(cols, 7 + extra_rows)
local screen = Screen.new(50, 7 + extra_height)
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {reverse = true}, -- focused cursor [1] = {reverse = true}, -- focused cursor
[2] = {background = 11}, -- unfocused cursor [2] = {background = 11}, -- unfocused cursor
@@ -61,23 +64,22 @@ local function screen_setup(extra_height, command)
execute('setlocal scrollback=10') execute('setlocal scrollback=10')
execute('startinsert') execute('startinsert')
if command == default_command then if command == default_command then
-- wait for "tty ready" to be printed before each test or the terminal may -- Wait for "tty ready" to be printed before each test or the terminal may
-- still be in canonical mode(will echo characters for example) -- still be in canonical mode (will echo characters for example).
-- local empty_line = (' '):rep(cols + 1)
local empty_line = ' '
local expected = { local expected = {
'tty ready ', 'tty ready'..(' '):rep(cols - 8),
'{1: } ', '{1: }' ..(' '):rep(cols),
empty_line, empty_line,
empty_line, empty_line,
empty_line, empty_line,
empty_line, empty_line,
} }
for _ = 1, extra_height do for _ = 1, extra_rows do
table.insert(expected, empty_line) table.insert(expected, empty_line)
end end
table.insert(expected, '{3:-- TERMINAL --} ') table.insert(expected, '{3:-- TERMINAL --}' .. ((' '):rep(cols - 13)))
screen:expect(table.concat(expected, '\n')) screen:expect(table.concat(expected, '\n'))
else else
wait() wait()

View File

@@ -17,7 +17,7 @@ describe('terminal scrollback', function()
before_each(function() before_each(function()
clear() clear()
screen = thelpers.screen_setup() screen = thelpers.screen_setup(nil, nil, 30)
end) end)
after_each(function() after_each(function()
@@ -33,26 +33,26 @@ describe('terminal scrollback', function()
table.insert(lines, '') table.insert(lines, '')
feed_data(lines) feed_data(lines)
screen:expect([[ screen:expect([[
line26 | line26 |
line27 | line27 |
line28 | line28 |
line29 | line29 |
line30 | line30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end) end)
it('will delete extra lines at the top', function() it('will delete extra lines at the top', function()
feed('<c-\\><c-n>gg') feed('<c-\\><c-n>gg')
screen:expect([[ screen:expect([[
^line16 | ^line16 |
line17 | line17 |
line18 | line18 |
line19 | line19 |
line20 | line20 |
line21 | line21 |
| |
]]) ]])
end) end)
end) end)
@@ -61,13 +61,13 @@ describe('terminal scrollback', function()
before_each(function() before_each(function()
feed_data({'line1', 'line2', 'line3', 'line4', ''}) feed_data({'line1', 'line2', 'line3', 'line4', ''})
screen:expect([[ screen:expect([[
tty ready | tty ready |
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end) end)
@@ -76,13 +76,13 @@ describe('terminal scrollback', function()
it('will hide the top line', function() it('will hide the top line', function()
screen:expect([[ screen:expect([[
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
line5 | line5 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(7, curbuf('line_count')) eq(7, curbuf('line_count'))
end) end)
@@ -92,46 +92,46 @@ describe('terminal scrollback', function()
it('will hide the top 4 lines', function() it('will hide the top 4 lines', function()
screen:expect([[ screen:expect([[
line3 | line3 |
line4 | line4 |
line5 | line5 |
line6 | line6 |
line7 | line7 |
line8{1: } | line8{1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('<c-\\><c-n>6k') feed('<c-\\><c-n>6k')
screen:expect([[ screen:expect([[
^line2 | ^line2 |
line3 | line3 |
line4 | line4 |
line5 | line5 |
line6 | line6 |
line7 | line7 |
| |
]]) ]])
feed('gg') feed('gg')
screen:expect([[ screen:expect([[
^tty ready | ^tty ready |
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
line5 | line5 |
| |
]]) ]])
feed('G') feed('G')
screen:expect([[ screen:expect([[
line3 | line3 |
line4 | line4 |
line5 | line5 |
line6 | line6 |
line7 | line7 |
^line8{2: } | ^line8{2: } |
| |
]]) ]])
end) end)
end) end)
@@ -142,12 +142,12 @@ describe('terminal scrollback', function()
local function will_hide_top_line() local function will_hide_top_line()
screen:try_resize(screen._width, screen._height - 1) screen:try_resize(screen._width, screen._height - 1)
screen:expect([[ screen:expect([[
line2 | line2 |
line3 | line3 |
line4 | line4 |
rows: 5, cols: 50 | rows: 5, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end end
@@ -161,18 +161,18 @@ describe('terminal scrollback', function()
it('will hide the top 3 lines', function() it('will hide the top 3 lines', function()
screen:expect([[ screen:expect([[
rows: 5, cols: 50 | rows: 5, cols: 30 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(8, curbuf('line_count')) eq(8, curbuf('line_count'))
feed('<c-\\><c-n>3k') feed('<c-\\><c-n>3k')
screen:expect([[ screen:expect([[
^line4 | ^line4 |
rows: 5, cols: 50 | rows: 5, cols: 30 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
| |
]]) ]])
end) end)
end) end)
@@ -187,11 +187,11 @@ describe('terminal scrollback', function()
local function will_delete_last_two_lines() local function will_delete_last_two_lines()
screen:expect([[ screen:expect([[
tty ready | tty ready |
rows: 4, cols: 50 | rows: 4, cols: 30 |
{1: } | {1: } |
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(4, curbuf('line_count')) eq(4, curbuf('line_count'))
end end
@@ -206,25 +206,25 @@ describe('terminal scrollback', function()
it('will delete the last line and hide the first', function() it('will delete the last line and hide the first', function()
screen:expect([[ screen:expect([[
rows: 4, cols: 50 | rows: 4, cols: 30 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(4, curbuf('line_count')) eq(4, curbuf('line_count'))
feed('<c-\\><c-n>gg') feed('<c-\\><c-n>gg')
screen:expect([[ screen:expect([[
^tty ready | ^tty ready |
rows: 4, cols: 50 | rows: 4, cols: 30 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
| |
]]) ]])
feed('a') feed('a')
screen:expect([[ screen:expect([[
rows: 4, cols: 50 | rows: 4, cols: 30 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end) end)
end) end)
@@ -235,20 +235,20 @@ describe('terminal scrollback', function()
before_each(function() before_each(function()
feed_data({'line1', 'line2', 'line3', 'line4', ''}) feed_data({'line1', 'line2', 'line3', 'line4', ''})
screen:expect([[ screen:expect([[
tty ready | tty ready |
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
screen:try_resize(screen._width, screen._height - 3) screen:try_resize(screen._width, screen._height - 3)
screen:expect([[ screen:expect([[
line4 | line4 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(7, curbuf('line_count')) eq(7, curbuf('line_count'))
end) end)
@@ -257,11 +257,11 @@ describe('terminal scrollback', function()
local function pop_then_push() local function pop_then_push()
screen:try_resize(screen._width, screen._height + 1) screen:try_resize(screen._width, screen._height + 1)
screen:expect([[ screen:expect([[
line4 | line4 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
rows: 4, cols: 50 | rows: 4, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end end
@@ -276,26 +276,26 @@ describe('terminal scrollback', function()
local function pop3_then_push1() local function pop3_then_push1()
screen:expect([[ screen:expect([[
line2 | line2 |
line3 | line3 |
line4 | line4 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
rows: 4, cols: 50 | rows: 4, cols: 30 |
rows: 7, cols: 50 | rows: 7, cols: 30 |
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(9, curbuf('line_count')) eq(9, curbuf('line_count'))
feed('<c-\\><c-n>gg') feed('<c-\\><c-n>gg')
screen:expect([[ screen:expect([[
^tty ready | ^tty ready |
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
rows: 4, cols: 50 | rows: 4, cols: 30 |
| |
]]) ]])
end end
@@ -310,18 +310,18 @@ describe('terminal scrollback', function()
it('will show all lines and leave a blank one at the end', function() it('will show all lines and leave a blank one at the end', function()
screen:expect([[ screen:expect([[
tty ready | tty ready |
line1 | line1 |
line2 | line2 |
line3 | line3 |
line4 | line4 |
rows: 3, cols: 50 | rows: 3, cols: 30 |
rows: 4, cols: 50 | rows: 4, cols: 30 |
rows: 7, cols: 50 | rows: 7, cols: 30 |
rows: 11, cols: 50 | rows: 11, cols: 30 |
{1: } | {1: } |
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
-- since there's an empty line after the cursor, the buffer line -- since there's an empty line after the cursor, the buffer line
-- count equals the terminal screen height -- count equals the terminal screen height
@@ -336,29 +336,29 @@ end)
describe('terminal prints more lines than the screen height and exits', function() describe('terminal prints more lines than the screen height and exits', function()
it('will push extra lines to scrollback', function() it('will push extra lines to scrollback', function()
clear() clear()
local screen = Screen.new(50, 7) local screen = Screen.new(30, 7)
screen:attach({rgb=false}) screen:attach({rgb=false})
execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert') execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert')
wait() wait()
screen:expect([[ screen:expect([[
line6 | line6 |
line7 | line7 |
line8 | line8 |
line9 | line9 |
| |
[Process exited 0] | [Process exited 0] |
-- TERMINAL -- | -- TERMINAL -- |
]]) ]])
feed('<cr>') feed('<cr>')
-- closes the buffer correctly after pressing a key -- closes the buffer correctly after pressing a key
screen:expect([[ screen:expect([[
^ | ^ |
~ | ~ |
~ | ~ |
~ | ~ |
~ | ~ |
~ | ~ |
| |
]]) ]])
end) end)
end) end)