Skip to content

Commit

Permalink
Merge pull request neovim#31168 from bfredl/noattach
Browse files Browse the repository at this point in the history
fix(tests): needing two calls to setup a screen is cringe
  • Loading branch information
bfredl authored Nov 14, 2024
2 parents 40dee8a + e61228a commit 7d771c3
Show file tree
Hide file tree
Showing 161 changed files with 128 additions and 606 deletions.
5 changes: 0 additions & 5 deletions test/functional/api/buffer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions test/functional/api/extmark_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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' })
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/functional/api/menu_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('update_menu notification', function()
before_each(function()
clear()
screen = Screen.new()
screen:attach()
end)

local function expect_sent(expected)
Expand Down
8 changes: 2 additions & 6 deletions test/functional/api/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
Expand All @@ -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'))
Expand All @@ -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')
Expand Down
23 changes: 2 additions & 21 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand All @@ -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 = [[
Expand Down Expand Up @@ -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)
Expand All @@ -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([[
Expand Down Expand Up @@ -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 = [[
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -2461,7 +2454,6 @@ describe('API', function()

before_each(function()
screen = Screen.new(40, 8)
screen:attach()
end)

it('can show one line', function()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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] = {
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -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]])
Expand Down Expand Up @@ -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 = [[
Expand Down Expand Up @@ -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 }))
Expand Down
6 changes: 0 additions & 6 deletions test/functional/api/window_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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>')
Expand Down Expand Up @@ -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([[
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)'
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/functional/autocmd/autocmd_oldtest_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('oldtests', function()
-- oldtest: Test_delete_ml_get_errors()
it('no ml_get error with TextChanged autocommand and delete', function()
local screen = Screen.new(75, 10)
screen:attach()
screen:add_extra_attr_ids {
[100] = { background = Screen.colors.Cyan1 },
}
Expand Down
3 changes: 0 additions & 3 deletions test/functional/autocmd/autocmd_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ describe('autocmd', function()
-- Check redrawing and API accesses to this window.

local screen = Screen.new(50, 10)
screen:attach()

source([[
function! Doit()
Expand Down Expand Up @@ -333,7 +332,6 @@ describe('autocmd', function()

it('`aucmd_win` cannot be changed into a normal window #13699', function()
local screen = Screen.new(50, 10)
screen:attach()

-- Create specific layout and ensure it's left unchanged.
-- Use vim._with on a hidden buffer so aucmd_win is used.
Expand Down Expand Up @@ -498,7 +496,6 @@ describe('autocmd', function()

it(':doautocmd does not warn "No matching autocommands" #10689', function()
local screen = Screen.new(32, 3)
screen:attach()

feed(':doautocmd User Foo<cr>')
screen:expect {
Expand Down
1 change: 0 additions & 1 deletion test/functional/autocmd/cmdline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('cmdline autocommands', function()
it('handles errors correctly', function()
clear()
local screen = Screen.new(72, 8)
screen:attach()
command("autocmd CmdlineEnter * echoerr 'FAIL'")
command("autocmd CmdlineLeave * echoerr 'very error'")

Expand Down
Loading

0 comments on commit 7d771c3

Please sign in to comment.