mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
fix(tests): needing two calls to setup a screen is cringe
Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session.
This commit is contained in:
@@ -125,7 +125,6 @@ describe('api/buf', function()
|
||||
|
||||
it('cursor position is maintained consistently with viewport', function()
|
||||
local screen = Screen.new(20, 12)
|
||||
screen:attach()
|
||||
|
||||
local lines = { 'line1', 'line2', 'line3', 'line4', 'line5', 'line6' }
|
||||
local buf = api.nvim_get_current_buf()
|
||||
@@ -211,7 +210,6 @@ describe('api/buf', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
screen = Screen.new(20, 12)
|
||||
screen:attach()
|
||||
api.nvim_buf_set_lines(
|
||||
0,
|
||||
0,
|
||||
@@ -735,7 +733,6 @@ describe('api/buf', function()
|
||||
|
||||
it("set_lines of invisible buffer doesn't move cursor in current window", function()
|
||||
local screen = Screen.new(20, 5)
|
||||
screen:attach()
|
||||
|
||||
insert([[
|
||||
Who would win?
|
||||
@@ -1689,7 +1686,6 @@ describe('api/buf', function()
|
||||
|
||||
it('correctly marks changed region for redraw #13890', function()
|
||||
local screen = Screen.new(20, 5)
|
||||
screen:attach()
|
||||
|
||||
insert([[
|
||||
AAA
|
||||
@@ -1742,7 +1738,6 @@ describe('api/buf', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
screen = Screen.new(20, 12)
|
||||
screen:attach()
|
||||
api.nvim_buf_set_lines(
|
||||
0,
|
||||
0,
|
||||
|
||||
@@ -455,7 +455,6 @@ describe('API/extmarks', function()
|
||||
|
||||
it('join works when no marks are present', function()
|
||||
screen = Screen.new(15, 10)
|
||||
screen:attach()
|
||||
feed('a<cr>1<esc>')
|
||||
feed('kJ')
|
||||
-- This shouldn't seg fault
|
||||
@@ -508,7 +507,6 @@ describe('API/extmarks', function()
|
||||
it('marks move with char inserts', function()
|
||||
-- insertchar in edit.c (the ins_str branch)
|
||||
screen = Screen.new(15, 10)
|
||||
screen:attach()
|
||||
set_extmark(ns, marks[1], 0, 3)
|
||||
feed('0')
|
||||
insert('abc')
|
||||
@@ -1726,7 +1724,6 @@ describe('API/extmarks', function()
|
||||
|
||||
it('invalidated marks are deleted', function()
|
||||
screen = Screen.new(40, 6)
|
||||
screen:attach()
|
||||
feed('dd6iaaa bbb ccc<CR><ESC>gg')
|
||||
api.nvim_set_option_value('signcolumn', 'auto:2', {})
|
||||
set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 })
|
||||
@@ -1811,7 +1808,6 @@ describe('API/extmarks', function()
|
||||
|
||||
it('respects priority', function()
|
||||
screen = Screen.new(15, 10)
|
||||
screen:attach()
|
||||
|
||||
set_extmark(ns, marks[1], 0, 0, {
|
||||
hl_group = 'Comment',
|
||||
@@ -1983,7 +1979,6 @@ describe('API/win_extmark', function()
|
||||
|
||||
it('sends and only sends ui-watched marks to ui', function()
|
||||
screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
-- should send this
|
||||
set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
|
||||
-- should not send this
|
||||
@@ -2006,7 +2001,6 @@ describe('API/win_extmark', function()
|
||||
|
||||
it('sends multiple ui-watched marks to ui', function()
|
||||
screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
feed('15A!<Esc>')
|
||||
-- should send all of these
|
||||
set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = 'overlay' })
|
||||
@@ -2052,7 +2046,6 @@ describe('API/win_extmark', function()
|
||||
|
||||
it('updates ui-watched marks', function()
|
||||
screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
-- should send this
|
||||
set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
|
||||
-- should not send this
|
||||
@@ -2096,8 +2089,7 @@ describe('API/win_extmark', function()
|
||||
end)
|
||||
|
||||
it('sends ui-watched to splits', function()
|
||||
screen = Screen.new(20, 8)
|
||||
screen:attach({ ext_multigrid = true })
|
||||
screen = Screen.new(20, 8, { ext_multigrid = true })
|
||||
-- should send this
|
||||
set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
|
||||
-- should not send this
|
||||
|
||||
@@ -11,7 +11,6 @@ describe('update_menu notification', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new()
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
local function expect_sent(expected)
|
||||
|
||||
@@ -18,8 +18,7 @@ describe('nvim_ui_attach()', function()
|
||||
end)
|
||||
|
||||
it('handles very large width/height #2180', function()
|
||||
local screen = Screen.new(999, 999)
|
||||
screen:attach()
|
||||
local _ = Screen.new(999, 999)
|
||||
eq(999, eval('&lines'))
|
||||
eq(999, eval('&columns'))
|
||||
end)
|
||||
@@ -64,8 +63,7 @@ describe('nvim_ui_attach()', function()
|
||||
eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_set_option', 'rgb', true))
|
||||
eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_detach'))
|
||||
|
||||
local screen = Screen.new()
|
||||
screen:attach({ rgb = false })
|
||||
local _ = Screen.new(nil, nil, { rgb = false })
|
||||
eq(
|
||||
'UI already attached to channel: 1',
|
||||
pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb = false })
|
||||
@@ -82,7 +80,6 @@ it('autocmds UIEnter/UILeave', function()
|
||||
autocmd VimEnter * call add(g:evs, "VimEnter")
|
||||
]])
|
||||
local screen = Screen.new()
|
||||
screen:attach()
|
||||
eq({ chan = 1 }, eval('g:uienter_ev'))
|
||||
screen:detach()
|
||||
eq({ chan = 1 }, eval('g:uileave_ev'))
|
||||
@@ -96,7 +93,6 @@ end)
|
||||
it('autocmds VimSuspend/VimResume #22041', function()
|
||||
clear()
|
||||
local screen = Screen.new()
|
||||
screen:attach()
|
||||
exec([[
|
||||
let g:ev = []
|
||||
autocmd VimResume * :call add(g:ev, 'r')
|
||||
|
||||
@@ -366,7 +366,6 @@ describe('API', function()
|
||||
|
||||
it('displays messages when opts.output=false', function()
|
||||
local screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
api.nvim_exec2("echo 'hello'", { output = false })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
@@ -379,7 +378,6 @@ describe('API', function()
|
||||
|
||||
it("doesn't display messages when output=true", function()
|
||||
local screen = Screen.new(40, 6)
|
||||
screen:attach()
|
||||
api.nvim_exec2("echo 'hello'", { output = true })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
@@ -1278,7 +1276,6 @@ describe('API', function()
|
||||
end)
|
||||
it('pasting with empty last chunk in Cmdline mode', function()
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
feed(':')
|
||||
api.nvim_paste('Foo', true, 1)
|
||||
api.nvim_paste('', true, 3)
|
||||
@@ -1290,7 +1287,6 @@ describe('API', function()
|
||||
end)
|
||||
it('pasting text with control characters in Cmdline mode', function()
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
feed(':')
|
||||
api.nvim_paste('normal! \023\022\006\027', true, -1)
|
||||
screen:expect([[
|
||||
@@ -1675,7 +1671,6 @@ describe('API', function()
|
||||
eq({ 1, 5 }, api.nvim_win_get_cursor(0))
|
||||
|
||||
local screen = Screen.new(60, 3)
|
||||
screen:attach()
|
||||
eq(1, eval('v:hlsearch'))
|
||||
screen:expect {
|
||||
grid = [[
|
||||
@@ -2130,7 +2125,6 @@ describe('API', function()
|
||||
|
||||
it('does not complete ("interrupt") `d` #3732', function()
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
command('set listchars=eol:$')
|
||||
command('set list')
|
||||
feed('ia<cr>b<cr>c<cr><Esc>kkk')
|
||||
@@ -2391,7 +2385,6 @@ describe('API', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
it('prints long messages correctly #20534', function()
|
||||
@@ -2461,7 +2454,6 @@ describe('API', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
it('can show one line', function()
|
||||
@@ -2543,7 +2535,6 @@ describe('API', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
it('shows only one return prompt after all lines are shown', function()
|
||||
@@ -3100,8 +3091,7 @@ describe('API', function()
|
||||
eq({}, api.nvim_list_uis())
|
||||
end)
|
||||
it('returns attached UIs', function()
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach({ override = true })
|
||||
local screen = Screen.new(20, 4, { override = true })
|
||||
local expected = {
|
||||
{
|
||||
chan = 1,
|
||||
@@ -3129,8 +3119,7 @@ describe('API', function()
|
||||
eq(expected, api.nvim_list_uis())
|
||||
|
||||
screen:detach()
|
||||
screen = Screen.new(44, 99)
|
||||
screen:attach({ rgb = false })
|
||||
screen = Screen.new(44, 99, { rgb = false }) -- luacheck: ignore
|
||||
expected[1].rgb = false
|
||||
expected[1].override = false
|
||||
expected[1].width = 44
|
||||
@@ -3165,7 +3154,6 @@ describe('API', function()
|
||||
eq(1, api.nvim_get_current_buf())
|
||||
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
api.nvim_buf_set_lines(2, 0, -1, true, { 'some text' })
|
||||
api.nvim_set_current_buf(2)
|
||||
screen:expect(
|
||||
@@ -3229,7 +3217,6 @@ describe('API', function()
|
||||
eq(1, api.nvim_get_current_buf())
|
||||
|
||||
local screen = Screen.new(20, 4)
|
||||
screen:attach()
|
||||
|
||||
--
|
||||
-- Editing a scratch-buffer does NOT change its properties.
|
||||
@@ -3591,7 +3578,6 @@ describe('API', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
command('highlight Statement gui=bold guifg=Brown')
|
||||
command('highlight Special guifg=SlateBlue')
|
||||
end)
|
||||
@@ -3654,7 +3640,6 @@ describe('API', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new(100, 35)
|
||||
screen:attach()
|
||||
screen:add_extra_attr_ids {
|
||||
[100] = { background = tonumber('0xffff40'), bg_indexed = true },
|
||||
[101] = {
|
||||
@@ -3933,7 +3918,6 @@ describe('API', function()
|
||||
command('set readonly')
|
||||
eq({ str = '[RO]', width = 4 }, api.nvim_eval_statusline('%r', { maxwidth = 5 }))
|
||||
local screen = Screen.new(80, 24)
|
||||
screen:attach()
|
||||
command('set showcmd')
|
||||
feed('1234')
|
||||
screen:expect({ any = '1234' })
|
||||
@@ -4591,7 +4575,6 @@ describe('API', function()
|
||||
end)
|
||||
it('does not interfere with printing line in Ex mode #19400', function()
|
||||
local screen = Screen.new(60, 7)
|
||||
screen:attach()
|
||||
insert([[
|
||||
foo
|
||||
bar]])
|
||||
@@ -5048,7 +5031,6 @@ describe('API', function()
|
||||
|
||||
it("doesn't display messages when output=true", function()
|
||||
local screen = Screen.new(40, 6)
|
||||
screen:attach()
|
||||
api.nvim_cmd({ cmd = 'echo', args = { [['hello']] } }, { output = true })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
@@ -5131,7 +5113,6 @@ describe('API', function()
|
||||
|
||||
it('nvim__redraw', function()
|
||||
local screen = Screen.new(60, 5)
|
||||
screen:attach()
|
||||
eq('at least one action required', pcall_err(api.nvim__redraw, {}))
|
||||
eq('at least one action required', pcall_err(api.nvim__redraw, { buf = 0 }))
|
||||
eq('at least one action required', pcall_err(api.nvim__redraw, { win = 0 }))
|
||||
|
||||
@@ -170,7 +170,6 @@ describe('API/win', function()
|
||||
|
||||
it('updates the screen, and also when the window is unfocused', function()
|
||||
local screen = Screen.new(30, 9)
|
||||
screen:attach()
|
||||
|
||||
insert('prologue')
|
||||
feed('100o<esc>')
|
||||
@@ -281,7 +280,6 @@ describe('API/win', function()
|
||||
|
||||
it('updates cursorline and statusline ruler in non-current window', function()
|
||||
local screen = Screen.new(60, 8)
|
||||
screen:attach()
|
||||
command('set ruler')
|
||||
command('set cursorline')
|
||||
insert([[
|
||||
@@ -314,7 +312,6 @@ describe('API/win', function()
|
||||
|
||||
it('updates cursorcolumn in non-current window', function()
|
||||
local screen = Screen.new(60, 8)
|
||||
screen:attach()
|
||||
command('set cursorcolumn')
|
||||
insert([[
|
||||
aaa
|
||||
@@ -857,7 +854,6 @@ describe('API/win', function()
|
||||
it('with two diff windows', function()
|
||||
local X = api.nvim_get_vvar('maxcol')
|
||||
local screen = Screen.new(45, 22)
|
||||
screen:attach()
|
||||
exec([[
|
||||
set diffopt+=context:2 number
|
||||
let expr = 'printf("%08d", v:val) .. repeat("!", v:val)'
|
||||
@@ -975,7 +971,6 @@ describe('API/win', function()
|
||||
it('with wrapped lines', function()
|
||||
local X = api.nvim_get_vvar('maxcol')
|
||||
local screen = Screen.new(45, 22)
|
||||
screen:attach()
|
||||
exec([[
|
||||
set number cpoptions+=n
|
||||
call setline(1, repeat([repeat('foobar-', 36)], 3))
|
||||
@@ -2557,7 +2552,6 @@ describe('API/win', function()
|
||||
|
||||
it('updates statusline when moving bottom split', function()
|
||||
local screen = Screen.new(10, 10)
|
||||
screen:attach()
|
||||
exec([[
|
||||
set laststatus=0
|
||||
belowright split
|
||||
|
||||
Reference in New Issue
Block a user