aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/window_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-09-27 22:33:24 +0800
committerGitHub <noreply@github.com>2024-09-27 14:33:24 +0000
commitf55213ce0e2b0053ded8416e8ae922a0e406012f (patch)
tree9cb764c0922dccb0fada755a8723340327329643 /test/functional/api/window_spec.lua
parenteea6b84a87fb72d66f83e8b5c440764ccbdf69b5 (diff)
downloadrneovim-f55213ce0e2b0053ded8416e8ae922a0e406012f.tar.gz
rneovim-f55213ce0e2b0053ded8416e8ae922a0e406012f.tar.bz2
rneovim-f55213ce0e2b0053ded8416e8ae922a0e406012f.zip
fix(api): fix crash/leak with float title/footer on error (#30543)
Diffstat (limited to 'test/functional/api/window_spec.lua')
-rw-r--r--test/functional/api/window_spec.lua77
1 files changed, 76 insertions, 1 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 63cde9dfb2..135b24fa5f 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -164,7 +164,7 @@ describe('API/win', function()
eq('typing\n some dumb text', curbuf_contents())
end)
- it('does not leak memory when using invalid window ID with invalid pos', function()
+ it('no memory leak when using invalid window ID with invalid pos', function()
eq('Invalid window id: 1', pcall_err(api.nvim_win_set_cursor, 1, { 'b\na' }))
end)
@@ -1809,6 +1809,38 @@ describe('API/win', function()
eq(topdir .. '/Xacd', fn.getcwd())
end)
end)
+
+ it('no memory leak with valid title and invalid footer', function()
+ eq(
+ 'title/footer must be string or array',
+ pcall_err(api.nvim_open_win, 0, false, {
+ relative = 'editor',
+ row = 5,
+ col = 5,
+ height = 5,
+ width = 5,
+ border = 'single',
+ title = { { 'TITLE' } },
+ footer = 0,
+ })
+ )
+ end)
+
+ it('no memory leak with invalid title and valid footer', function()
+ eq(
+ 'title/footer must be string or array',
+ pcall_err(api.nvim_open_win, 0, false, {
+ relative = 'editor',
+ row = 5,
+ col = 5,
+ height = 5,
+ width = 5,
+ border = 'single',
+ title = 0,
+ footer = { { 'FOOTER' } },
+ })
+ )
+ end)
end)
describe('set_config', function()
@@ -2801,5 +2833,48 @@ describe('API/win', function()
command('redraw!')
assert_alive()
end)
+
+ describe('no crash or memory leak', function()
+ local win
+
+ before_each(function()
+ win = api.nvim_open_win(0, false, {
+ relative = 'editor',
+ row = 5,
+ col = 5,
+ height = 5,
+ width = 5,
+ border = 'single',
+ title = { { 'OLD_TITLE' } },
+ footer = { { 'OLD_FOOTER' } },
+ })
+ end)
+
+ it('with valid title and invalid footer', function()
+ eq(
+ 'title/footer must be string or array',
+ pcall_err(api.nvim_win_set_config, win, {
+ title = { { 'NEW_TITLE' } },
+ footer = 0,
+ })
+ )
+ command('redraw!')
+ assert_alive()
+ eq({ { 'OLD_TITLE' } }, api.nvim_win_get_config(win).title)
+ end)
+
+ it('with invalid title and valid footer', function()
+ eq(
+ 'title/footer must be string or array',
+ pcall_err(api.nvim_win_set_config, win, {
+ title = 0,
+ footer = { { 'NEW_FOOTER' } },
+ })
+ )
+ command('redraw!')
+ assert_alive()
+ eq({ { 'OLD_FOOTER' } }, api.nvim_win_get_config(win).footer)
+ end)
+ end)
end)
end)