multigrid: add multigrid screen tests

This commit is contained in:
Utkarsh Maheshwari 2018-12-18 12:50:44 +01:00 committed by Björn Linse
parent 1f8afe15a4
commit ebe16cd9bd
5 changed files with 942 additions and 11 deletions

View File

@ -72,10 +72,10 @@ local function screen_setup(extra_rows, command, cols)
if command == default_command then
-- Wait for "tty ready" to be printed before each test or the terminal may
-- still be in canonical mode (will echo characters for example).
local empty_line = (' '):rep(cols + 1)
local empty_line = (' '):rep(cols)
local expected = {
'tty ready'..(' '):rep(cols - 8),
'{1: }' ..(' '):rep(cols),
'tty ready'..(' '):rep(cols - 9),
'{1: }' ..(' '):rep(cols - 1),
empty_line,
empty_line,
empty_line,
@ -85,8 +85,8 @@ local function screen_setup(extra_rows, command, cols)
table.insert(expected, empty_line)
end
table.insert(expected, '{3:-- TERMINAL --}' .. ((' '):rep(cols - 13)))
screen:expect(table.concat(expected, '\n'))
table.insert(expected, '{3:-- TERMINAL --}' .. ((' '):rep(cols - 14)))
screen:expect(table.concat(expected, '|\n')..'|')
else
-- This eval also acts as a wait().
if 0 == nvim('eval', "exists('b:terminal_job_id')") then

View File

@ -401,7 +401,7 @@ describe('tui FocusGained/FocusLost', function()
-- Exit cmdline-mode. Redraws from timers/events are blocked during
-- cmdline-mode, so the buffer won't be updated until we exit cmdline-mode.
feed_data('\n')
screen:expect{any='lost'..(' '):rep(46)..'\ngained'}
screen:expect{any='lost'..(' '):rep(46)..'|\ngained'}
end)
end)

View File

@ -0,0 +1,932 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local spawn, set_session = helpers.spawn, helpers.set_session
local feed, command, insert = helpers.feed, helpers.command, helpers.insert
local eq = helpers.eq
-- Note 1:
-- Global grid i.e. "grid 1" shows some unwanted elements because they are
-- not cleared when they are expected to be drawn over by window grids.
describe('multigrid screen', function()
local screen
local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
'--embed'}
before_each(function()
local screen_nvim = spawn(nvim_argv)
set_session(screen_nvim)
screen = Screen.new()
screen:attach({ext_multigrid=true})
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1},
[2] = {foreground = Screen.colors.Magenta},
[3] = {foreground = Screen.colors.Brown, bold = true},
[4] = {foreground = Screen.colors.SlateBlue},
[5] = {bold = true, foreground = Screen.colors.SlateBlue},
[6] = {foreground = Screen.colors.Cyan4},
[7] = {bold = true},
[8] = {underline = true, bold = true, foreground = Screen.colors.SlateBlue},
[9] = {foreground = Screen.colors.SlateBlue, underline = true},
[10] = {foreground = Screen.colors.Red},
[11] = {bold = true, reverse = true},
[12] = {reverse = true},
[13] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
})
screen.win_position = {}
end)
after_each(function()
screen:detach()
end)
it('default initial screen', function()
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('positions windows correctly', function()
command('vsplit')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]], nil, nil, function()
eq({
[2] = { win = 1000, startrow = 0, startcol = 27, width = 26, height = 12 },
[3] = { win = 1001, startrow = 0, startcol = 0, width = 26, height = 12 }
}, screen.win_position)
end)
command('wincmd l')
command('split')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:}{11:[No Name] }|
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:[No Name] [No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]], nil, nil, function()
eq({
[2] = { win = 1000, startrow = 7, startcol = 27, width = 26, height = 5 },
[3] = { win = 1001, startrow = 0, startcol = 0, width = 26, height = 12 },
[4] = { win = 1002, startrow = 0, startcol = 27, width = 26, height = 6 }
}, screen.win_position)
end)
command('wincmd h')
command('q')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }|
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]], nil, nil, function()
eq({
[2] = { win = 1000, startrow = 7, startcol = 0, width = 53, height = 5 },
[4] = { win = 1002, startrow = 0, startcol = 0, width = 53, height = 6 }
}, screen.win_position)
end)
end)
describe('split', function ()
describe('horizontally', function ()
it('allocates grids', function ()
command('sp')
screen:expect([[
## grid 1
|
|
|
|
|
|
{11:[No Name] }|
|
|
|
|
|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('resizes grids', function ()
command('sp')
command('resize 8')
-- see "Note 1" for info about why there are three statuslines
screen:expect([[
## grid 1
|
|
|
|
|
|
{11:[No Name] }|
|
{11:[No Name] }|
|
|
|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('splits vertically', function()
command('sp')
command('vsp')
command('vsp')
screen:expect([[
## grid 1
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{11:[No Name] }{12:[No Name] [No Name] }|
|
|
|
|
|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 5
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
insert('hello')
screen:expect([[
## grid 1
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{11:[No Name] [+] }{12:[No Name] [+] [No Name] [+] }|
|
|
|
|
|
{12:[No Name] [+] }|
|
## grid 2
hello |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
hello |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
hello |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 5
hell^o |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('closes splits', function ()
command('sp')
command('q')
screen:expect([[
## grid 1
|
|
|
|
|
|
{11:[No Name] }|
|
|
|
|
|
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)
describe('vertically', function ()
it('allocates grids', function ()
command('vsp')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('resizes grids', function ()
command('vsp')
command('vertical resize 10')
-- see "Note 1" for info about why there are two vseps
screen:expect([[
## grid 1
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{11:<No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('splits horizontally', function ()
command('vsp')
command('sp')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:[No Name] [No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
insert('hello')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] [+] }{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:[No Name] [+] [No Name] [+] }|
|
## grid 2
hello |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
hello |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
hell^o |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('closes splits', function ()
command('vsp')
command('q')
-- see "Note 1" for info about why there is a vsep
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)
end)
describe('on resize', function ()
it('rebuilds all grids', function ()
screen:try_resize(25, 6)
screen:expect([[
## grid 1
|
|
|
|
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('has minimum width/height values', function()
screen:try_resize(1, 1)
screen:expect([[
## grid 1
|
{11:[No Name] }|
|
## grid 2
^ |
]])
feed('<esc>:ls')
screen:expect([[
## grid 1
|
{11:[No Name] }|
:ls^ |
## grid 2
|
]])
end)
end)
describe('grid of smaller inner size', function()
it('is rendered correctly', function()
screen:try_resize_grid(2, 8, 5)
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)
describe('grid of bigger inner size', function()
it('is rendered correctly', function()
screen:try_resize_grid(2, 80, 20)
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] }|
|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)
describe('with resized grid', function()
before_each(function()
screen:try_resize_grid(2, 60, 20)
end)
it('gets written till grid width', function()
insert(('a'):rep(60).."\n")
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] [+] }|
|
## grid 2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('wraps with grid width', function()
insert(('b'):rep(80).."\n")
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] [+] }|
|
## grid 2
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
bbbbbbbbbbbbbbbbbbbb |
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('displays messages with default grid width', function()
command('echomsg "this is a very very very very very very very very'..
' long message"')
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] }|
this is a very very very...ry very very long message |
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('creates folds with grid width', function()
insert('this is a fold\nthis is inside fold\nthis is outside fold')
feed('kzfgg')
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
{11:[No Name] [+] }|
|
## grid 2
{13:^+-- 2 lines: this is a fold································}|
this is outside fold |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)
end)

View File

@ -349,7 +349,6 @@ function Screen:expect(expected, attr_ids, attr_ignore)
-- value.
grid = dedent(grid:gsub('\n[ ]+$', ''), 0)
for row in grid:gmatch('[^\n]+') do
row = row:sub(1, #row - 1) -- Last char must be the screen delimiter.
table.insert(expected_rows, row)
end
end
@ -382,7 +381,7 @@ function Screen:expect(expected, attr_ids, attr_ignore)
return (
'Failed to match any screen lines.\n'
.. 'Expected (anywhere): "' .. expected.any .. '"\n'
.. 'Actual:\n |' .. table.concat(actual_rows, '|\n |') .. '|\n\n')
.. 'Actual:\n |' .. table.concat(actual_rows, '\n |') .. '\n\n')
end
end
@ -402,8 +401,8 @@ function Screen:expect(expected, attr_ids, attr_ignore)
actual_rows[i] = '*' .. actual_rows[i]
return (
'Row ' .. tostring(i) .. ' did not match.\n'
..'Expected:\n |'..table.concat(msg_expected_rows, '|\n |')..'|\n'
..'Actual:\n |'..table.concat(actual_rows, '|\n |')..'|\n\n'..[[
..'Expected:\n |'..table.concat(msg_expected_rows, '\n |')..'\n'
..'Actual:\n |'..table.concat(actual_rows, '\n |')..'\n\n'..[[
To print the expect() call that would assert the current screen state, use
screen:snapshot_util(). In case of non-deterministic failures, use
screen:redraw_debug() to show all intermediate screen states. ]])

View File

@ -165,7 +165,7 @@ describe("'wildmenu'", function()
feed([[:<Tab>]]) -- Invoke wildmenu.
-- Check only the last 2 lines, because the shell output is
-- system-dependent.
expect_stay_unchanged{any='! # & < = > @ > \n:!^'}
expect_stay_unchanged{any='! # & < = > @ > |\n:!^'}
end)
end)