multigrid: test refactor

This commit is contained in:
Björn Linse 2018-11-17 18:23:42 +01:00
parent 13f74635fa
commit ed3da23cf4
2 changed files with 359 additions and 269 deletions

View File

@ -44,18 +44,18 @@ describe('multigrid screen', function()
it('default initial screen', function()
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
@ -78,18 +78,18 @@ describe('multigrid screen', function()
command('vsplit')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:[No Name] }|
|
## grid 2
@ -128,18 +128,18 @@ describe('multigrid screen', function()
command('split')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:}{11:[No Name] }|
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}[4:--------------------------]|
[3:--------------------------]{12:│}{11:[No Name] }|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{12:[No Name] [No Name] }|
|
## grid 2
@ -179,18 +179,18 @@ describe('multigrid screen', function()
command('q')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
{11:[No Name] }|
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
@ -220,18 +220,18 @@ describe('multigrid screen', function()
command('sp')
screen:expect([[
## grid 1
|
|
|
|
|
|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
{11:[No Name] }|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
@ -253,21 +253,20 @@ describe('multigrid screen', function()
it('resizes grids', function ()
command('sp')
command('resize 8')
-- see "Note 1" for info about why there are three statuslines
screen:expect([[
## grid 1
|
|
|
|
|
|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
{11:[No Name] }|
|
{11:[No Name] }|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
@ -292,18 +291,18 @@ describe('multigrid screen', function()
command('vsp')
screen:expect([[
## grid 1
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
{11:[No Name] }{12:[No Name] [No Name] }|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
@ -337,18 +336,18 @@ describe('multigrid screen', function()
insert('hello')
screen:expect([[
## grid 1
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
{12:} {12:} |
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
[5:--------------------]{12:│}[4:----------------]{12:│}[3:---------------]|
{11:[No Name] [+] }{12:[No Name] [+] [No Name] [+] }|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] [+] }|
|
## grid 2
@ -382,21 +381,51 @@ describe('multigrid screen', function()
end)
it('closes splits', function ()
command('sp')
screen:expect([[
## grid 1
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
[3:-----------------------------------------------------]|
{11:[No Name] }|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('q')
screen:expect([[
## grid 1
|
|
|
|
|
|
{11:[No Name] }|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
@ -421,18 +450,18 @@ describe('multigrid screen', function()
command('vsp')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:[No Name] }|
|
## grid 2
@ -469,18 +498,18 @@ describe('multigrid screen', function()
-- 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:} |
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
[3:----------]{12:│}[2:------------------------------------------]|
{11:<No Name] }{12:[No Name] }|
|
## grid 2
@ -516,18 +545,18 @@ describe('multigrid screen', function()
command('sp')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] }{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{12:[No Name] [No Name] }|
|
## grid 2
@ -560,18 +589,18 @@ describe('multigrid screen', function()
insert('hello')
screen:expect([[
## grid 1
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{11:[No Name] [+] }{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
{12:} |
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
[4:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] [+] }{12:}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{12:[No Name] [+] [No Name] [+] }|
|
## grid 2
@ -600,26 +629,68 @@ describe('multigrid screen', function()
{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:} |
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{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:~ }|
]])
command('q')
screen:expect([[
## grid 1
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
@ -645,10 +716,10 @@ describe('multigrid screen', function()
screen:try_resize(25, 6)
screen:expect([[
## grid 1
|
|
|
|
[2:-------------------------]|
[2:-------------------------]|
[2:-------------------------]|
[2:-------------------------]|
{11:[No Name] }|
|
## grid 2
@ -663,7 +734,7 @@ describe('multigrid screen', function()
screen:try_resize(1, 1)
screen:expect([[
## grid 1
|
[2:------------]|
{11:[No Name] }|
|
## grid 2
@ -673,7 +744,7 @@ describe('multigrid screen', function()
feed('<esc>:ls')
screen:expect([[
## grid 1
|
[2:------------]|
{11:[No Name] }|
:ls^ |
## grid 2
@ -687,18 +758,18 @@ describe('multigrid screen', function()
screen:try_resize_grid(2, 8, 5)
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
@ -716,18 +787,18 @@ describe('multigrid screen', function()
screen:try_resize_grid(2, 80, 20)
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
@ -763,18 +834,18 @@ describe('multigrid screen', function()
insert(('a'):rep(60).."\n")
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] [+] }|
|
## grid 2
@ -805,18 +876,18 @@ describe('multigrid screen', function()
insert(('b'):rep(80).."\n")
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] [+] }|
|
## grid 2
@ -848,18 +919,18 @@ describe('multigrid screen', function()
' long message"')
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] }|
this is a very very very...ry very very long message |
## grid 2
@ -891,18 +962,18 @@ describe('multigrid screen', function()
feed('kzfgg')
screen:expect([[
## grid 1
|
|
|
|
|
|
|
|
|
|
|
|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11:[No Name] [+] }|
|
## grid 2

View File

@ -704,7 +704,7 @@ end
function Screen:_handle_grid_destroy(grid)
self._grids[grid] = nil
if self._multigrid then
if self._options.ext_multigrid then
assert(self.win_position[grid])
self.win_position[grid] = nil
end
@ -810,7 +810,6 @@ function Screen:_handle_win_pos(grid, win, startrow, startcol, width, height)
width = width,
height = height
}
-- TODO(utkarshme): Take apt action
end
function Screen:_handle_win_hide(grid)
@ -981,31 +980,51 @@ function Screen:_clear_row_section(grid, rownum, startcol, stopcol)
end
end
function Screen:_row_repr(row, attr_state, cursor)
function Screen:_row_repr(gridnr, rownr, attr_state, cursor)
local rv = {}
local current_attr_id
for i = 1, #row do
local attrs = row[i].attrs
if self._options.ext_linegrid then
attrs = attrs[(self._options.rgb and 1) or 2]
local i = 1
local has_windows = self._options.ext_multigrid and gridnr == 1
local row = self._grids[gridnr].rows[rownr]
while i <= #row do
local did_window = false
if has_windows then
for id,pos in pairs(self.win_position) do
if i-1 == pos.startcol and pos.startrow <= rownr-1 and rownr-1 < pos.startrow + pos.height then
if current_attr_id then
-- close current attribute bracket
table.insert(rv, '}')
current_attr_id = nil
end
table.insert(rv, '['..id..':'..string.rep('-',pos.width)..']')
i = i + pos.width
did_window = true
end
end
end
local attr_id = self:_get_attr_id(attr_state, attrs, row[i].hl_id)
if current_attr_id and attr_id ~= current_attr_id then
-- close current attribute bracket, add it before any whitespace
-- up to the current cell
-- table.insert(rv, backward_find_meaningful(rv, i), '}')
table.insert(rv, '}')
current_attr_id = nil
if not did_window then
local attrs = row[i].attrs
if self._options.ext_linegrid then
attrs = attrs[(self._options.rgb and 1) or 2]
end
local attr_id = self:_get_attr_id(attr_state, attrs, row[i].hl_id)
if current_attr_id and attr_id ~= current_attr_id then
-- close current attribute bracket
table.insert(rv, '}')
current_attr_id = nil
end
if not current_attr_id and attr_id then
-- open a new attribute bracket
table.insert(rv, '{' .. attr_id .. ':')
current_attr_id = attr_id
end
if not self._busy and cursor and self._cursor.col == i then
table.insert(rv, '^')
end
table.insert(rv, row[i].text)
i = i + 1
end
if not current_attr_id and attr_id then
-- open a new attribute bracket
table.insert(rv, '{' .. attr_id .. ':')
current_attr_id = attr_id
end
if not self._busy and cursor and self._cursor.col == i then
table.insert(rv, '^')
end
table.insert(rv, row[i].text)
end
if current_attr_id then
table.insert(rv, '}')
@ -1090,7 +1109,7 @@ function Screen:render(headers, attr_state, preview)
for i = 1, grid.height do
local cursor = self._cursor.grid == igrid and self._cursor.row == i
local prefix = (headers or preview) and " " or ""
table.insert(rv, prefix..self:_row_repr(grid.rows[i], attr_state, cursor).."|")
table.insert(rv, prefix..self:_row_repr(igrid, i, attr_state, cursor).."|")
end
end
return rv