aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/autocmd_spec.lua28
-rw-r--r--test/functional/api/vim_spec.lua12
-rw-r--r--test/functional/lua/vim_spec.lua33
-rw-r--r--test/functional/plugin/lsp_spec.lua12
-rw-r--r--test/functional/treesitter/highlight_spec.lua40
5 files changed, 118 insertions, 7 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua
index 372cbf2c30..a58ca00a75 100644
--- a/test/functional/api/autocmd_spec.lua
+++ b/test/functional/api/autocmd_spec.lua
@@ -154,6 +154,34 @@ describe('autocmd api', function()
eq(1, #aus, aus)
end)
end)
+
+ it('removes an autocommand if the callback returns true', function()
+ meths.set_var("some_condition", false)
+
+ exec_lua [[
+ vim.api.nvim_create_autocmd("User", {
+ pattern = "Test",
+ desc = "A test autocommand",
+ callback = function()
+ return vim.g.some_condition
+ end,
+ })
+ ]]
+
+ meths.do_autocmd("User", {pattern = "Test"})
+ eq({{
+ buflocal = false,
+ command = 'A test autocommand',
+ desc = 'A test autocommand',
+ event = 'User',
+ id = 1,
+ once = false,
+ pattern = 'Test',
+ }}, meths.get_autocmds({event = "User", pattern = "Test"}))
+ meths.set_var("some_condition", true)
+ meths.do_autocmd("User", {pattern = "Test"})
+ eq({}, meths.get_autocmds({event = "User", pattern = "Test"}))
+ end)
end)
describe('nvim_get_autocmds', function()
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index af6872760a..ed9d915954 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -6,6 +6,7 @@ local assert_alive = helpers.assert_alive
local NIL = helpers.NIL
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
local command = helpers.command
+local exec = helpers.exec
local eval = helpers.eval
local expect = helpers.expect
local funcs = helpers.funcs
@@ -1271,6 +1272,17 @@ describe('API', function()
eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
+ exec([[
+ function Test()
+ endfunction
+ function s:Test()
+ endfunction
+ let g:Unknown_func = function('Test')
+ let g:Unknown_script_func = function('s:Test')
+ ]])
+ eq(NIL, meths.get_var('Unknown_func'))
+ eq(NIL, meths.get_var('Unknown_script_func'))
+
-- Check if autoload works properly
local pathsep = helpers.get_pathsep()
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 5b4daf02ea..38cb54fbc6 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -1043,6 +1043,17 @@ describe('lua stdlib', function()
exec_lua([[vim.api.nvim_get_var('funcs').add()]])
eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]]))
+ exec([[
+ function Test()
+ endfunction
+ function s:Test()
+ endfunction
+ let g:Unknown_func = function('Test')
+ let g:Unknown_script_func = function('s:Test')
+ ]])
+ eq(NIL, exec_lua([[return vim.g.Unknown_func]]))
+ eq(NIL, exec_lua([[return vim.g.Unknown_script_func]]))
+
-- Check if autoload works properly
local pathsep = helpers.get_pathsep()
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
@@ -1136,6 +1147,17 @@ describe('lua stdlib', function()
exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]])
eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]]))
+ exec([[
+ function Test()
+ endfunction
+ function s:Test()
+ endfunction
+ let b:Unknown_func = function('Test')
+ let b:Unknown_script_func = function('s:Test')
+ ]])
+ eq(NIL, exec_lua([[return vim.b.Unknown_func]]))
+ eq(NIL, exec_lua([[return vim.b.Unknown_script_func]]))
+
exec_lua [[
vim.cmd "vnew"
]]
@@ -1219,6 +1241,17 @@ describe('lua stdlib', function()
exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]])
eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]]))
+ exec([[
+ function Test()
+ endfunction
+ function s:Test()
+ endfunction
+ let w:Unknown_func = function('Test')
+ let w:Unknown_script_func = function('s:Test')
+ ]])
+ eq(NIL, exec_lua([[return vim.w.Unknown_func]]))
+ eq(NIL, exec_lua([[return vim.w.Unknown_script_func]]))
+
exec_lua [[
vim.cmd "vnew"
]]
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index eab520948f..6cda9af0f4 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2374,18 +2374,16 @@ describe('LSP', function()
end)
describe('lsp.util.get_effective_tabstop', function()
- local function test_tabstop(tabsize, softtabstop)
+ local function test_tabstop(tabsize, shiftwidth)
exec_lua(string.format([[
- vim.api.nvim_buf_set_option(0, 'softtabstop', %d)
+ vim.api.nvim_buf_set_option(0, 'shiftwidth', %d)
vim.api.nvim_buf_set_option(0, 'tabstop', 2)
- vim.api.nvim_buf_set_option(0, 'shiftwidth', 3)
- ]], softtabstop))
+ ]], shiftwidth))
eq(tabsize, exec_lua('return vim.lsp.util.get_effective_tabstop()'))
end
- it('with softtabstop = 1', function() test_tabstop(1, 1) end)
- it('with softtabstop = 0', function() test_tabstop(2, 0) end)
- it('with softtabstop = -1', function() test_tabstop(3, -1) end)
+ it('with shiftwidth = 1', function() test_tabstop(1, 1) end)
+ it('with shiftwidth = 0', function() test_tabstop(2, 0) end)
end)
describe('vim.lsp.buf.outgoing_calls', function()
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index ed28d8a37d..5ec0a8a060 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -672,6 +672,46 @@ describe('treesitter highlighting', function()
]]}
end)
+ it("supports conceal attribute", function()
+ if pending_c_parser(pending) then return end
+ insert(hl_text)
+
+ -- conceal can be empty or a single cchar.
+ exec_lua [=[
+ vim.opt.cole = 2
+ local parser = vim.treesitter.get_parser(0, "c")
+ test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = [[
+ ("static" @keyword
+ (set! conceal "R"))
+
+ ((identifier) @Identifier
+ (set! conceal "")
+ (eq? @Identifier "lstate"))
+ ]]}})
+ ]=]
+
+ screen:expect{grid=[[
+ /// Schedule Lua callback on main loop's event queue |
+ {4:R} int nlua_schedule(lua_State *const ) |
+ { |
+ if (lua_type(, 1) != LUA_TFUNCTION |
+ || != ) { |
+ lua_pushliteral(, "vim.schedule: expected function"); |
+ return lua_error(); |
+ } |
+ |
+ LuaRef cb = nlua_ref(, 1); |
+ |
+ multiqueue_put(main_loop.events, nlua_schedule_event, |
+ 1, (void *)(ptrdiff_t)cb); |
+ return 0; |
+ ^} |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
+
it("hl_map has the correct fallback behavior", function()
exec_lua [[
local hl_map = vim.treesitter.highlighter.hl_map