aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/diagnostic_spec.lua22
-rw-r--r--test/functional/lua/luaeval_spec.lua5
-rw-r--r--test/functional/lua/overrides_spec.lua45
-rw-r--r--test/functional/lua/vim_spec.lua33
4 files changed, 82 insertions, 23 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index f9647f5b6a..4226bcebac 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -128,6 +128,28 @@ describe('vim.diagnostic', function()
eq('Diagnostic #1', result[1].message)
end)
+ it('removes diagnostics from the cache when a buffer is removed', function()
+ eq(2, exec_lua [[
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ local other_bufnr = vim.fn.bufadd('test | test')
+ local lines = vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, -1, true)
+ vim.api.nvim_buf_set_lines(other_bufnr, 0, 1, false, lines)
+ vim.cmd('bunload! ' .. other_bufnr)
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Diagnostic #1', 1, 1, 1, 1),
+ make_error('Diagnostic #2', 2, 1, 2, 1),
+ })
+ vim.diagnostic.set(diagnostic_ns, other_bufnr, {
+ make_error('Diagnostic #3', 3, 1, 3, 1),
+ })
+ vim.api.nvim_set_current_buf(other_bufnr)
+ vim.opt_local.buflisted = true
+ vim.cmd('bwipeout!')
+ return #vim.diagnostic.get()
+ ]])
+ end)
+
it('resolves buffer number 0 to the current buffer', function()
eq(2, exec_lua [[
vim.api.nvim_set_current_buf(diagnostic_bufnr)
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 1322155595..9f313eab9e 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -467,7 +467,6 @@ describe('v:lua', function()
end
end
end
- vim.api.nvim_buf_set_option(0, 'omnifunc', 'v:lua.mymod.omni')
]])
end)
@@ -515,6 +514,7 @@ describe('v:lua', function()
[5] = {bold = true, foreground = Screen.colors.SeaGreen4},
})
screen:attach()
+ meths.buf_set_option(0, 'omnifunc', 'v:lua.mymod.omni')
feed('isome st<c-x><c-o>')
screen:expect{grid=[[
some stuff^ |
@@ -526,6 +526,9 @@ describe('v:lua', function()
{1:~ }|
{4:-- Omni completion (^O^N^P) }{5:match 1 of 3} |
]]}
+ meths.set_option('operatorfunc', 'v:lua.mymod.noisy')
+ feed('<Esc>g@g@')
+ eq("hey line", meths.get_current_line())
end)
it('supports packages', function()
diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua
index 9b51af1eec..32c1615a45 100644
--- a/test/functional/lua/overrides_spec.lua
+++ b/test/functional/lua/overrides_spec.lua
@@ -144,13 +144,14 @@ describe('debug.debug', function()
before_each(function()
screen = Screen.new()
screen:attach()
- screen:set_default_attr_ids({
- [0] = {bold=true, foreground=255},
- E = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
- cr = {bold = true, foreground = Screen.colors.SeaGreen4},
- })
- command("set display-=msgsep")
+ 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()
command([[lua
function Test(a)
@@ -160,9 +161,8 @@ describe('debug.debug', function()
end
]])
feed(':lua Test()\n')
- screen:expect([[
- {0:~ }|
- {0:~ }|
+ screen:expect{grid=[[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
@@ -173,11 +173,13 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
+ {1: }|
nil |
lua_debug> ^ |
- ]])
+ ]]}
feed('print("TEST")\n')
screen:expect([[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
@@ -186,8 +188,7 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
nil |
lua_debug> print("TEST") |
TEST |
@@ -195,10 +196,10 @@ describe('debug.debug', function()
]])
feed('<C-c>')
screen:expect{grid=[[
+ |
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
nil |
lua_debug> print("TEST") |
TEST |
@@ -212,6 +213,7 @@ describe('debug.debug', function()
]]}
feed('<C-l>:lua Test()\n')
screen:expect([[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
@@ -222,19 +224,18 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
nil |
lua_debug> ^ |
]])
feed('\n')
screen:expect{grid=[[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
nil |
lua_debug> |
{E:E5108: Error executing lua [string ":lua"]:5: attempt}|
@@ -268,6 +269,7 @@ describe('debug.debug', function()
feed("conttt<cr>") -- misspelled cont; invalid syntax
screen:expect{grid=[[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
@@ -276,8 +278,7 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
lua_debug> conttt |
{E:E5115: Error while loading debug string: (debug comma}|
{E:nd):1: '=' expected near '<eof>'} |
@@ -286,14 +287,14 @@ describe('debug.debug', function()
feed("cont<cr>") -- exactly "cont", exit now
screen:expect{grid=[[
+ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
+ {1: }|
lua_debug> conttt |
{E:E5115: Error while loading debug string: (debug comma}|
{E:nd):1: '=' expected near '<eof>'} |
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 2b249b7a69..f2fb661b70 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -2721,6 +2721,39 @@ describe('lua stdlib', function()
]]
end)
end)
+
+ describe('vim.iconv', function()
+ it('can convert strings', function()
+ eq('hello', exec_lua[[
+ return vim.iconv('hello', 'latin1', 'utf-8')
+ ]])
+ end)
+
+ it('can validate arguments', function()
+ eq({false, 'Expected at least 3 arguments'}, exec_lua[[
+ return {pcall(vim.iconv, 'hello')}
+ ]])
+
+ eq({false, 'bad argument #3 to \'?\' (expected string)'}, exec_lua[[
+ return {pcall(vim.iconv, 'hello', 'utf-8', true)}
+ ]])
+ end)
+
+ it('can handle bad encodings', function()
+ eq(NIL, exec_lua[[
+ return vim.iconv('hello', 'foo', 'bar')
+ ]])
+ end)
+
+ it('can handle strings with NUL bytes', function()
+ eq(7, exec_lua[[
+ local a = string.char(97, 98, 99, 0, 100, 101, 102) -- abc\0def
+ return string.len(vim.iconv(a, 'latin1', 'utf-8'))
+ ]])
+ end)
+
+ end)
+
end)
describe('lua: builtin modules', function()