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:
@@ -344,7 +344,6 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
|
||||
it('setting extmark in on_lines callback works', function()
|
||||
local screen = Screen.new(40, 6)
|
||||
screen:attach()
|
||||
|
||||
api.nvim_buf_set_lines(0, 0, -1, true, { 'aaa', 'bbb', 'ccc' })
|
||||
exec_lua(function()
|
||||
|
||||
@@ -111,7 +111,6 @@ describe(':lua', function()
|
||||
|
||||
it('can show multiline error messages', function()
|
||||
local screen = Screen.new(40, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
@@ -204,7 +203,6 @@ describe(':lua', function()
|
||||
|
||||
it('with range', function()
|
||||
local screen = Screen.new(40, 10)
|
||||
screen:attach()
|
||||
api.nvim_buf_set_lines(0, 0, 0, 0, { 'nonsense', 'function x() print "hello" end', 'x()' })
|
||||
|
||||
-- ":{range}lua" fails on invalid Lua code.
|
||||
|
||||
@@ -18,7 +18,6 @@ describe('vim.hl.range', function()
|
||||
screen:add_extra_attr_ids({
|
||||
[100] = { foreground = Screen.colors.Blue, background = Screen.colors.Yellow, bold = true },
|
||||
})
|
||||
screen:attach()
|
||||
api.nvim_set_option_value('list', true, {})
|
||||
api.nvim_set_option_value('listchars', 'eol:$', {})
|
||||
api.nvim_buf_set_lines(0, 0, -1, true, {
|
||||
|
||||
@@ -65,7 +65,6 @@ describe('vim.uv', function()
|
||||
|
||||
it('is API safe', function()
|
||||
local screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
|
||||
@@ -510,7 +510,6 @@ describe('v:lua', function()
|
||||
|
||||
it('works in func options', function()
|
||||
local screen = Screen.new(60, 8)
|
||||
screen:attach()
|
||||
api.nvim_set_option_value('omnifunc', 'v:lua.mymod.omni', {})
|
||||
feed('isome st<c-x><c-o>')
|
||||
screen:expect{grid=[[
|
||||
|
||||
@@ -158,7 +158,6 @@ describe('print', function()
|
||||
|
||||
it('blank line in message works', function()
|
||||
local screen = Screen.new(40, 8)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[0] = { bold = true, foreground = Screen.colors.Blue },
|
||||
[1] = { bold = true, foreground = Screen.colors.SeaGreen },
|
||||
@@ -196,7 +195,6 @@ describe('debug.debug', function()
|
||||
|
||||
before_each(function()
|
||||
screen = Screen.new()
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids {
|
||||
[0] = { bold = true, foreground = 255 },
|
||||
[1] = { bold = true, reverse = true },
|
||||
|
||||
@@ -39,7 +39,6 @@ describe('vim.secure', function()
|
||||
|
||||
it('works', function()
|
||||
local screen = Screen.new(80, 8)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
||||
[2] = { bold = true, reverse = true },
|
||||
|
||||
@@ -17,7 +17,6 @@ describe('thread', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
it('entry func is executed in protected mode', function()
|
||||
@@ -257,7 +256,6 @@ describe('threadpool', function()
|
||||
|
||||
it('with invalid return value', function()
|
||||
local screen = Screen.new(50, 10)
|
||||
screen:attach()
|
||||
|
||||
exec_lua [[
|
||||
local work = vim.uv.new_work(function() return {} end, function() end)
|
||||
|
||||
@@ -41,7 +41,6 @@ describe('vim.ui_attach', function()
|
||||
[6] = { reverse = true, bold = true },
|
||||
[7] = { background = Screen.colors.Yellow1 },
|
||||
})
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
local function expect_events(expected)
|
||||
@@ -251,8 +250,7 @@ describe('vim.ui_attach', function()
|
||||
|
||||
it('error in callback is logged', function()
|
||||
clear({ env = { NVIM_LOG_FILE = testlog } })
|
||||
local screen = Screen.new()
|
||||
screen:attach()
|
||||
local _ = Screen.new()
|
||||
exec_lua([[
|
||||
local ns = vim.api.nvim_create_namespace('testspace')
|
||||
vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end)
|
||||
|
||||
@@ -637,7 +637,6 @@ describe('lua stdlib', function()
|
||||
matches('big failure\nvery async', remove_trace(eval('v:errmsg')))
|
||||
|
||||
local screen = Screen.new(60, 5)
|
||||
screen:attach()
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
@@ -1403,7 +1402,6 @@ describe('lua stdlib', function()
|
||||
end)
|
||||
|
||||
local screen = Screen.new(50, 7)
|
||||
screen:attach()
|
||||
exec_lua([[
|
||||
timer = vim.uv.new_timer()
|
||||
timer:start(20, 0, function ()
|
||||
@@ -2130,7 +2128,6 @@ describe('lua stdlib', 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 = [[
|
||||
@@ -3401,7 +3398,6 @@ stack traceback:
|
||||
|
||||
it('callback is not invoked recursively #30752', function()
|
||||
local screen = Screen.new(60, 10)
|
||||
screen:attach()
|
||||
exec_lua([[
|
||||
vim.on_key(function(key, typed)
|
||||
vim.api.nvim_echo({
|
||||
@@ -3779,7 +3775,6 @@ stack traceback:
|
||||
|
||||
it('fails in fast callbacks #26122', function()
|
||||
local screen = Screen.new(80, 10)
|
||||
screen:attach()
|
||||
exec_lua([[
|
||||
local timer = vim.uv.new_timer()
|
||||
timer:start(0, 0, function()
|
||||
@@ -3797,7 +3792,6 @@ stack traceback:
|
||||
|
||||
it('vim.notify_once', function()
|
||||
local screen = Screen.new(60, 5)
|
||||
screen:attach()
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
@@ -3994,7 +3988,6 @@ stack traceback:
|
||||
it('updates ruler if cursor moved', function()
|
||||
-- Fixed for win_execute in vim-patch:8.1.2124, but should've applied to nvim_win_call too!
|
||||
local screen = Screen.new(30, 5)
|
||||
screen:attach()
|
||||
exec_lua [[
|
||||
_G.api = vim.api
|
||||
vim.opt.ruler = true
|
||||
@@ -4137,7 +4130,6 @@ stack traceback:
|
||||
|
||||
it('vim.lua_omnifunc', function()
|
||||
local screen = Screen.new(60, 5)
|
||||
screen:attach()
|
||||
command [[ set omnifunc=v:lua.vim.lua_omnifunc ]]
|
||||
|
||||
-- Note: the implementation is shared with lua command line completion.
|
||||
|
||||
@@ -1029,7 +1029,6 @@ describe('vim._with', function()
|
||||
[1] = { bold = true, reverse = true },
|
||||
[2] = { bold = true, foreground = Screen.colors.Blue },
|
||||
}
|
||||
screen:attach()
|
||||
exec_lua [[ vim._with({ silent = true }, function() vim.cmd.echo('"ccc"') end) ]]
|
||||
screen:expect [[
|
||||
^ |
|
||||
@@ -1178,7 +1177,6 @@ describe('vim._with', function()
|
||||
[1] = { reverse = true },
|
||||
[2] = { bold = true, reverse = true },
|
||||
}
|
||||
screen:attach()
|
||||
exec_lua [[
|
||||
vim.opt.ruler = true
|
||||
local lines = {}
|
||||
|
||||
Reference in New Issue
Block a user