aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/autocmd_spec.lua126
-rw-r--r--test/functional/api/vim_spec.lua12
-rw-r--r--test/functional/legacy/messages_spec.lua71
-rw-r--r--test/functional/ui/global_statusline_spec.lua27
-rw-r--r--test/functional/ui/input_spec.lua44
-rw-r--r--test/functional/ui/syntax_conceal_spec.lua53
-rw-r--r--test/functional/vimscript/timer_spec.lua2
7 files changed, 333 insertions, 2 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua
index 3b14ae9bf7..9fc0066819 100644
--- a/test/functional/api/autocmd_spec.lua
+++ b/test/functional/api/autocmd_spec.lua
@@ -334,6 +334,33 @@ describe('autocmd api', function()
local aus2 = meths.get_autocmds { group = auname, event = "InsertEnter" }
eq(0, #aus2)
end)
+
+ it('should respect nested', function()
+ local bufs = exec_lua [[
+ local count = 0
+ vim.api.nvim_create_autocmd("BufNew", {
+ once = false,
+ nested = true,
+ callback = function()
+ count = count + 1
+ if count > 5 then
+ return true
+ end
+
+ vim.cmd(string.format("new README_%s.md", count))
+ end
+ })
+
+ vim.cmd "new First.md"
+
+ return vim.api.nvim_list_bufs()
+ ]]
+
+ -- 1 for the first buffer
+ -- 2 for First.md
+ -- 3-7 for the 5 we make in the autocmd
+ eq({1, 2, 3, 4, 5, 6, 7}, bufs)
+ end)
end)
describe('groups', function()
@@ -782,6 +809,14 @@ describe('autocmd api', function()
eq(2, get_executed_count(), "No additional counts")
end)
+ it('can delete non-existent groups with pcall', function()
+ eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]])
+ eq('Vim:E367: No such group: "noexist"', pcall_err(meths.del_augroup_by_name, 'noexist'))
+
+ eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]])
+ eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312))
+ end)
+
it('groups work with once', function()
local augroup = "TestGroup"
@@ -945,4 +980,95 @@ describe('autocmd api', function()
eq(0, #meths.get_autocmds { event = 'BufReadPost' })
end)
end)
+
+ describe('nvim_clear_autocmd', function()
+ it('should clear based on event + pattern', function()
+ command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"')
+ command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"')
+
+ local search = { event = "InsertEnter", pattern = "*.txt" }
+ local before_delete = meths.get_autocmds(search)
+ eq(1, #before_delete)
+
+ local before_delete_all = meths.get_autocmds { event = search.event }
+ eq(2, #before_delete_all)
+
+ meths.clear_autocmd(search)
+ local after_delete = meths.get_autocmds(search)
+ eq(0, #after_delete)
+
+ local after_delete_all = meths.get_autocmds { event = search.event }
+ eq(1, #after_delete_all)
+ end)
+
+ it('should clear based on event', function()
+ command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"')
+ command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"')
+
+ local search = { event = "InsertEnter"}
+ local before_delete = meths.get_autocmds(search)
+ eq(2, #before_delete)
+
+ meths.clear_autocmd(search)
+ local after_delete = meths.get_autocmds(search)
+ eq(0, #after_delete)
+ end)
+
+ it('should clear based on pattern', function()
+ command('autocmd InsertEnter *.TestPat1 :echo "Enter 1"')
+ command('autocmd InsertLeave *.TestPat1 :echo "Leave 1"')
+ command('autocmd InsertEnter *.TestPat2 :echo "Enter 2"')
+ command('autocmd InsertLeave *.TestPat2 :echo "Leave 2"')
+
+ local search = { pattern = "*.TestPat1"}
+ local before_delete = meths.get_autocmds(search)
+ eq(2, #before_delete)
+ local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } }
+ eq(4, #before_delete_events)
+
+ meths.clear_autocmd(search)
+ local after_delete = meths.get_autocmds(search)
+ eq(0, #after_delete)
+
+ local after_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } }
+ eq(2, #after_delete_events)
+ end)
+
+ it('should allow clearing by buffer', function()
+ command('autocmd! InsertEnter')
+ command('autocmd InsertEnter <buffer> :echo "Enter Buffer"')
+ command('autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"')
+
+ local search = { event = "InsertEnter" }
+ local before_delete = meths.get_autocmds(search)
+ eq(2, #before_delete)
+
+ meths.clear_autocmd { buffer = 0 }
+ local after_delete = meths.get_autocmds(search)
+ eq(1, #after_delete)
+ eq("*.TestPat1", after_delete[1].pattern)
+ end)
+
+ it('should allow clearing by buffer and group', function()
+ command('augroup TestNvimClearAutocmds')
+ command(' au!')
+ command(' autocmd InsertEnter <buffer> :echo "Enter Buffer"')
+ command(' autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"')
+ command('augroup END')
+
+ local search = { event = "InsertEnter", group = "TestNvimClearAutocmds" }
+ local before_delete = meths.get_autocmds(search)
+ eq(2, #before_delete)
+
+ -- Doesn't clear without passing group.
+ meths.clear_autocmd { buffer = 0 }
+ local without_group = meths.get_autocmds(search)
+ eq(2, #without_group)
+
+ -- Doest clear with passing group.
+ meths.clear_autocmd { buffer = 0, group = search.group }
+ local with_group = meths.get_autocmds(search)
+ eq(1, #with_group)
+ end)
+ end)
end)
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index ed9d915954..e6ed0f939b 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1589,6 +1589,18 @@ describe('API', function()
feed(':digraphs<cr>')
eq({mode='rm', blocking=true}, nvim("get_mode"))
end)
+
+ it('after <Nop> mapping returns blocking=false #17257', function()
+ command('nnoremap <F2> <Nop>')
+ feed('<F2>')
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
+
+ it('after empty string <expr> mapping returns blocking=false #17257', function()
+ command('nnoremap <expr> <F2> ""')
+ feed('<F2>')
+ eq({mode='n', blocking=false}, nvim("get_mode"))
+ end)
end)
describe('RPC (K_EVENT)', function()
diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua
new file mode 100644
index 0000000000..34807a099c
--- /dev/null
+++ b/test/functional/legacy/messages_spec.lua
@@ -0,0 +1,71 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local command = helpers.command
+local exec = helpers.exec
+local feed = helpers.feed
+
+before_each(clear)
+
+describe('messages', function()
+ it('more prompt with control characters can be quit vim-patch:8.2.1844', function()
+ local screen = Screen.new(40, 6)
+ screen:set_default_attr_ids({
+ [1] = {foreground = Screen.colors.Blue}, -- SpecialKey
+ [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
+ [3] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+ command('set more')
+ feed([[:echom range(9999)->join("\x01")<CR>]])
+ screen:expect([[
+ 0{1:^A}1{1:^A}2{1:^A}3{1:^A}4{1:^A}5{1:^A}6{1:^A}7{1:^A}8{1:^A}9{1:^A}10{1:^A}11{1:^A}12|
+ {1:^A}13{1:^A}14{1:^A}15{1:^A}16{1:^A}17{1:^A}18{1:^A}19{1:^A}20{1:^A}21{1:^A}22|
+ {1:^A}23{1:^A}24{1:^A}25{1:^A}26{1:^A}27{1:^A}28{1:^A}29{1:^A}30{1:^A}31{1:^A}32|
+ {1:^A}33{1:^A}34{1:^A}35{1:^A}36{1:^A}37{1:^A}38{1:^A}39{1:^A}40{1:^A}41{1:^A}42|
+ {1:^A}43{1:^A}44{1:^A}45{1:^A}46{1:^A}47{1:^A}48{1:^A}49{1:^A}50{1:^A}51{1:^A}52|
+ {2:-- More --}^ |
+ ]])
+ feed('q')
+ screen:expect([[
+ ^ |
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ {3:~ }|
+ |
+ ]])
+ end)
+
+ it('fileinfo does not overwrite echo message vim-patch:8.2.4156', function()
+ local screen = Screen.new(40, 6)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+ exec([[
+ set shortmess-=F
+
+ file a.txt
+
+ hide edit b.txt
+ call setline(1, "hi")
+ setlocal modified
+
+ hide buffer a.txt
+
+ autocmd CursorHold * buf b.txt | w | echo "'b' written"
+ ]])
+ command('set updatetime=50')
+ feed('0$')
+ screen:expect([[
+ ^hi |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ 'b' written |
+ ]])
+ os.remove('b.txt')
+ end)
+end)
diff --git a/test/functional/ui/global_statusline_spec.lua b/test/functional/ui/global_statusline_spec.lua
index 6b37e5e2f1..f6821ec589 100644
--- a/test/functional/ui/global_statusline_spec.lua
+++ b/test/functional/ui/global_statusline_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, command, feed = helpers.clear, helpers.command, helpers.feed
+local eq, funcs, meths = helpers.eq, helpers.funcs, helpers.meths
describe('global statusline', function()
local screen
@@ -230,4 +231,30 @@ describe('global statusline', function()
[3] = {reverse = true, bold = true};
}}
end)
+
+ it('win_move_statusline() can reduce cmdheight to 1', function()
+ eq(1, meths.get_option('cmdheight'))
+ funcs.win_move_statusline(0, -1)
+ eq(2, meths.get_option('cmdheight'))
+ funcs.win_move_statusline(0, -1)
+ eq(3, meths.get_option('cmdheight'))
+ funcs.win_move_statusline(0, 1)
+ eq(2, meths.get_option('cmdheight'))
+ funcs.win_move_statusline(0, 1)
+ eq(1, meths.get_option('cmdheight'))
+ end)
+
+ it('mouse dragging can reduce cmdheight to 1', function()
+ command('set mouse=a')
+ meths.input_mouse('left', 'press', '', 0, 14, 10)
+ eq(1, meths.get_option('cmdheight'))
+ meths.input_mouse('left', 'drag', '', 0, 13, 10)
+ eq(2, meths.get_option('cmdheight'))
+ meths.input_mouse('left', 'drag', '', 0, 12, 10)
+ eq(3, meths.get_option('cmdheight'))
+ meths.input_mouse('left', 'drag', '', 0, 13, 10)
+ eq(2, meths.get_option('cmdheight'))
+ meths.input_mouse('left', 'drag', '', 0, 14, 10)
+ eq(1, meths.get_option('cmdheight'))
+ end)
end)
diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua
index f5ae228b1e..9df7531016 100644
--- a/test/functional/ui/input_spec.lua
+++ b/test/functional/ui/input_spec.lua
@@ -320,3 +320,47 @@ describe("event processing and input", function()
eq({'notification', 'stop', {}}, next_msg())
end)
end)
+
+describe('display is updated', function()
+ local screen
+ before_each(function()
+ screen = Screen.new(60, 8)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1}, -- NonText
+ [2] = {bold = true}, -- ModeMsg
+ })
+ screen:attach()
+ end)
+
+ it('in Insert mode after <Nop> mapping #17911', function()
+ command('imap <Plug>test <Nop>')
+ command('imap <F2> abc<CR><Plug>test')
+ feed('i<F2>')
+ screen:expect([[
+ abc |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end)
+
+ it('in Insert mode after empty string <expr> mapping #17911', function()
+ command('imap <expr> <Plug>test ""')
+ command('imap <F2> abc<CR><Plug>test')
+ feed('i<F2>')
+ screen:expect([[
+ abc |
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end)
+end)
diff --git a/test/functional/ui/syntax_conceal_spec.lua b/test/functional/ui/syntax_conceal_spec.lua
index 4e1852162f..92e5a5dd94 100644
--- a/test/functional/ui/syntax_conceal_spec.lua
+++ b/test/functional/ui/syntax_conceal_spec.lua
@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, command = helpers.clear, helpers.feed, helpers.command
local eq = helpers.eq
local insert = helpers.insert
+local poke_eventloop = helpers.poke_eventloop
describe('Screen', function()
local screen
@@ -911,7 +912,57 @@ describe('Screen', function()
{0:~ }|
|
]]}
- eq(grid_lines, {{2, 0, {{'c', 0, 3}}}})
+ eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
+ end)
+
+ it('K_EVENT should not cause extra redraws with concealcursor #13196', function()
+ command('set conceallevel=1')
+ command('set concealcursor=nv')
+ command('set redrawdebug+=nodelta')
+
+ insert([[
+ aaa
+ bbb
+ ccc
+ ]])
+ screen:expect{grid=[[
+ aaa |
+ bbb |
+ ccc |
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+
+ -- XXX: hack to get notifications, and check only a single line is
+ -- updated. Could use next_msg() also.
+ local orig_handle_grid_line = screen._handle_grid_line
+ local grid_lines = {}
+ function screen._handle_grid_line(self, grid, row, col, items)
+ table.insert(grid_lines, {row, col, items})
+ orig_handle_grid_line(self, grid, row, col, items)
+ end
+ feed('k')
+ screen:expect{grid=[[
+ aaa |
+ bbb |
+ ^ccc |
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
+ poke_eventloop() -- causes K_EVENT key
+ screen:expect_unchanged()
+ eq({{2, 0, {{'c', 0, 3}}}}, grid_lines)
end)
-- Copy of Test_cursor_column_in_concealed_line_after_window_scroll in
diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua
index 25e46062b7..20f2afb20f 100644
--- a/test/functional/vimscript/timer_spec.lua
+++ b/test/functional/vimscript/timer_spec.lua
@@ -273,7 +273,7 @@ describe('timers', function()
eq("Vim(call):E48: Not allowed in sandbox", exc_exec("sandbox call timer_start(0, 'Scary')"))
end)
- it('can be triggered after an empty string <expr> mapping', function()
+ it('can be triggered after an empty string <expr> mapping #17257', function()
local screen = Screen.new(40, 6)
screen:attach()
command([=[imap <expr> <F2> [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=])