fix(tests): use builtin default attributes in more places

This commit is contained in:
bfredl
2026-06-19 09:50:52 +02:00
parent 0639f6e41a
commit 90157d3790
9 changed files with 556 additions and 651 deletions

View File

@@ -159,20 +159,15 @@ describe('print', function()
it('blank line in message works', function()
local screen = Screen.new(40, 8)
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue },
[1] = { bold = true, foreground = Screen.colors.SeaGreen },
[2] = { bold = true, reverse = true },
})
feed([[:lua print('\na')<CR>]])
screen:expect {
grid = [[
|
{0:~ }|*3
{2: }|
{1:~ }|*3
{3: }|
|
a |
{1:Press ENTER or type command to continue}^ |
{6:Press ENTER or type command to continue}^ |
]],
}
feed('<CR>')
@@ -180,12 +175,12 @@ describe('print', function()
screen:expect {
grid = [[
|
{0:~ }|*2
{2: }|
{1:~ }|*2
{3: }|
b |
|
c |
{1:Press ENTER or type command to continue}^ |
{6:Press ENTER or type command to continue}^ |
]],
}
end)
@@ -196,12 +191,6 @@ describe('debug.debug', function()
before_each(function()
screen = Screen.new()
screen:set_default_attr_ids {
[0] = { bold = true, foreground = 255 },
[1] = { bold = true, reverse = true },
E = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
cr = { bold = true, foreground = Screen.colors.SeaGreen4 },
}
end)
it('works', function()
@@ -216,8 +205,8 @@ describe('debug.debug', function()
screen:expect {
grid = [[
|
{0:~ }|*10
{1: }|
{1:~ }|*10
{3: }|
nil |
lua_debug> ^ |
]],
@@ -225,8 +214,8 @@ describe('debug.debug', function()
feed('print("TEST")\n')
screen:expect([[
|
{0:~ }|*8
{1: }|
{1:~ }|*8
{3: }|
nil |
lua_debug> print("TEST") |
TEST |
@@ -235,40 +224,40 @@ describe('debug.debug', function()
feed('<C-c>')
screen:expect([[
|
{0:~ }|*2
{1: }|
{1:~ }|*2
{3: }|
nil |
lua_debug> print("TEST") |
TEST |
|
{E:E5108: Lua: [string ":lua"]:5: attempt to perform ari}|
{E:thmetic on local 'a' (a nil value)} |
{E:stack traceback:} |
{E: [string ":lua"]:5: in function 'Test'} |
{E: [string ":lua"]:1: in main chunk} |
Interrupt: {cr:Press ENTER or type command to continue}^ |
{9:E5108: Lua: [string ":lua"]:5: attempt to perform ari}|
{9:thmetic on local 'a' (a nil value)} |
{9:stack traceback:} |
{9: [string ":lua"]:5: in function 'Test'} |
{9: [string ":lua"]:1: in main chunk} |
Interrupt: {6:Press ENTER or type command to continue}^ |
]])
feed('<C-l>:lua Test()\n')
screen:expect([[
|
{0:~ }|*10
{1: }|
{1:~ }|*10
{3: }|
nil |
lua_debug> ^ |
]])
feed('\n')
screen:expect([[
|
{0:~ }|*4
{1: }|
{1:~ }|*4
{3: }|
nil |
lua_debug> |
{E:E5108: Lua: [string ":lua"]:5: attempt to perform ari}|
{E:thmetic on local 'a' (a nil value)} |
{E:stack traceback:} |
{E: [string ":lua"]:5: in function 'Test'} |
{E: [string ":lua"]:1: in main chunk} |
{cr:Press ENTER or type command to continue}^ |
{9:E5108: Lua: [string ":lua"]:5: attempt to perform ari}|
{9:thmetic on local 'a' (a nil value)} |
{9:stack traceback:} |
{9: [string ":lua"]:5: in function 'Test'} |
{9: [string ":lua"]:1: in main chunk} |
{6:Press ENTER or type command to continue}^ |
]])
end)
@@ -278,7 +267,7 @@ describe('debug.debug', function()
screen:expect {
grid = [[
|
{0:~ }|*12
{1:~ }|*12
lua_debug> ^ |
]],
}
@@ -286,32 +275,32 @@ describe('debug.debug', function()
feed('conttt<cr>') -- misspelled cont; invalid syntax
screen:expect([[
|
{0:~ }|*8
{1: }|
{1:~ }|*8
{3: }|
lua_debug> conttt |
{E:E5115: Loading Lua debug string: (debug command):1: '}|
{E:=' expected near '<eof>'} |
{9:E5115: Loading Lua debug string: (debug command):1: '}|
{9:=' expected near '<eof>'} |
lua_debug> ^ |
]])
feed('cont<cr>') -- exactly "cont", exit now
screen:expect([[
|
{0:~ }|*6
{1: }|
{1:~ }|*6
{3: }|
lua_debug> conttt |
{E:E5115: Loading Lua debug string: (debug command):1: '}|
{E:=' expected near '<eof>'} |
{9:E5115: Loading Lua debug string: (debug command):1: '}|
{9:=' expected near '<eof>'} |
lua_debug> cont |
x |
{cr:Press ENTER or type command to continue}^ |
{6:Press ENTER or type command to continue}^ |
]])
feed('<cr>')
screen:expect {
grid = [[
^ |
{0:~ }|*12
{1:~ }|*12
|
]],
}

View File

@@ -51,13 +51,6 @@ describe('vim.secure', function()
end)
it('regular file', function()
screen:set_default_attr_ids({
[1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = { bold = true, reverse = true },
[3] = { bold = true, foreground = Screen.colors.SeaGreen },
[4] = { reverse = true },
})
local cwd = fn.getcwd()
local msg = 'exrc: Found untrusted code. To enable it, choose (v)iew then run `:trust`:'
local path = vim.fs.joinpath(cwd, 'Xfile')
@@ -67,11 +60,11 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xfile'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: *}|
{3:]] .. path .. [[}{MATCH: *}|
{3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: *}|
{6:]] .. path .. [[}{MATCH: *}|
{6:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
]])
feed('d')
screen:expect([[
@@ -89,21 +82,21 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xfile'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: *}|
{3:]] .. path .. [[}{MATCH: *}|
{3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: *}|
{6:]] .. path .. [[}{MATCH: *}|
{6:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
]])
feed('v')
feed(':trust<CR>')
screen:expect([[
^let g:foobar = 42{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xfile') .. [[ [RO]{MATCH: +}}|
{3:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xfile') .. [[ [RO]{MATCH: +}}|
{MATCH: +}|
{1:~{MATCH: +}}|
{4:[No Name]{MATCH: +}}|
{2:[No Name]{MATCH: +}}|
Allowed in trust database: "]] .. vim.fs.joinpath(cwd, 'Xfile') .. [["{MATCH: +}|
]])
-- close the split for the next test below.
@@ -119,11 +112,11 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xfile'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: *}|
{3:]] .. path .. [[}{MATCH: *}|
{3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: *}|
{6:]] .. path .. [[}{MATCH: *}|
{6:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
]])
feed('i')
screen:expect([[
@@ -139,20 +132,20 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xfile'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: +}|
{3:]] .. path .. [[}{MATCH: *}|
{3:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: +}|
{6:]] .. path .. [[}{MATCH: *}|
{6:[i]gnore, (v)iew, (d)eny: }^{MATCH: +}|
]])
feed('v')
screen:expect([[
^let g:foobar = 42{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xfile') .. [[ [RO]{MATCH: +}}|
{3:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xfile') .. [[ [RO]{MATCH: +}}|
{MATCH: +}|
{1:~{MATCH: +}}|
{4:[No Name]{MATCH: +}}|
{2:[No Name]{MATCH: +}}|
{MATCH: +}|
]])
@@ -165,13 +158,6 @@ describe('vim.secure', function()
end)
it('directory', function()
screen:set_default_attr_ids({
[1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = { bold = true, reverse = true },
[3] = { bold = true, foreground = Screen.colors.SeaGreen },
[4] = { reverse = true },
})
local cwd = fn.getcwd()
local msg =
'exrc: Found untrusted code. DIRECTORY trust is decided only by name, not contents:'
@@ -182,11 +168,11 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xdir'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: +}|
{3:]] .. path .. [[}{MATCH: +}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: +}|
{6:]] .. path .. [[}{MATCH: +}|
{6:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
]])
feed('d')
screen:expect([[
@@ -204,11 +190,11 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xdir'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: +}|
{3:]] .. path .. [[}{MATCH: +}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: +}|
{6:]] .. path .. [[}{MATCH: +}|
{6:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
]])
feed('a')
screen:expect([[
@@ -228,11 +214,11 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xdir'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: +}|
{3:]] .. path .. [[}{MATCH: +}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: +}|
{6:]] .. path .. [[}{MATCH: +}|
{6:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
]])
feed('i')
screen:expect([[
@@ -248,20 +234,20 @@ describe('vim.secure', function()
screen:expect([[
{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:{MATCH: +}}|
{3:{MATCH: +}}|
:lua vim.secure.read('Xdir'){MATCH: +}|
{3:]] .. msg .. [[}{MATCH: +}|
{3:]] .. path .. [[}{MATCH: +}|
{3:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
{6:]] .. msg .. [[}{MATCH: +}|
{6:]] .. path .. [[}{MATCH: +}|
{6:[i]gnore, (v)iew, (d)eny, (a)llow: }^{MATCH: +}|
]])
feed('v')
screen:expect([[
^{MATCH: +}|
{1:~{MATCH: +}}|*2
{2:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xdir') .. [[ [RO]{MATCH: +}}|
{3:]] .. vim.fs.joinpath(fn.fnamemodify(cwd, ':~'), 'Xdir') .. [[ [RO]{MATCH: +}}|
{MATCH: +}|
{1:~{MATCH: +}}|
{4:[No Name]{MATCH: +}}|
{2:[No Name]{MATCH: +}}|
{MATCH: +}|
]])

View File

@@ -65,13 +65,6 @@ describe('vim.uv', function()
it('is API safe', function()
local screen = Screen.new(50, 10)
screen:set_default_attr_ids({
[1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = { bold = true, reverse = true },
[3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
[4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
[5] = { bold = true },
})
-- deferred API functions are disabled, as their safety can't be guaranteed
exec_lua([[
@@ -86,15 +79,15 @@ describe('vim.uv', function()
screen:expect([[
|
{2: }|
{3:Lua callback:} |
{3:[string "<nvim>"]:5: E5560: nvim_set_var must not }|
{3:be called in a fast event context} |
{3:stack traceback:} |
{3: [C]: in function 'nvim_set_var'} |
{3: [string "<nvim>"]:5: in function <[string }|
{3:"<nvim>"]:2>} |
{4:Press ENTER or type command to continue}^ |
{3: }|
{9:Lua callback:} |
{9:[string "<nvim>"]:5: E5560: nvim_set_var must not }|
{9:be called in a fast event context} |
{9:stack traceback:} |
{9: [C]: in function 'nvim_set_var'} |
{9: [string "<nvim>"]:5: in function <[string }|
{9:"<nvim>"]:2>} |
{6:Press ENTER or type command to continue}^ |
]])
feed('<cr>')
eq(false, eval("get(g:, 'valid', v:false)"))
@@ -151,7 +144,7 @@ describe('vim.uv', function()
end)
end)
screen:expect({ any = [[{3:Vim:E5560: Vimscript function must not be called i}]] })
screen:expect({ any = [[{9:Vim:E5560: Vimscript function must not be called i}]] })
feed('<cr>')
eq({ 1, nil }, exec_lua('return {_G.value, _G.unvalue}'))
end)

View File

@@ -1073,14 +1073,10 @@ describe('vim._with', function()
eq('', exec_capture('messages'))
local screen = Screen.new(20, 5)
screen:set_default_attr_ids {
[1] = { bold = true, reverse = true },
[2] = { bold = true, foreground = Screen.colors.Blue },
}
exec_lua [[ vim._with({ silent = true }, function() vim.cmd.echo('"ccc"') end) ]]
screen:expect [[
^ |
{2:~ }|*3
{1:~ }|*3
|
]]
end)
@@ -1229,10 +1225,6 @@ describe('vim._with', function()
it('updates ruler if cursor moved', function()
local screen = Screen.new(30, 5)
screen:set_default_attr_ids {
[1] = { reverse = true },
[2] = { bold = true, reverse = true },
}
exec_lua [[
vim.opt.ruler = true
local lines = {}
@@ -1245,9 +1237,9 @@ describe('vim._with', function()
]]
screen:expect [[
19 |
{1:< Name] [+] 20,1 3%}|
^19 |
{2:< Name] [+] 20,1 3%}|
^19 |
{3:< Name] [+] 20,1 3%}|
|
]]
exec_lua [[
@@ -1256,9 +1248,9 @@ describe('vim._with', function()
]]
screen:expect [[
99 |
{1:< Name] [+] 100,1 19%}|
{2:< Name] [+] 100,1 19%}|
^19 |
{2:< Name] [+] 20,1 3%}|
{3:< Name] [+] 20,1 3%}|
|
]]
end)