parent
996a057fb9
commit
316c29bbf3
|
@ -15,9 +15,7 @@ before_each(clear)
|
||||||
describe('treesitter API', function()
|
describe('treesitter API', function()
|
||||||
-- error tests not requiring a parser library
|
-- error tests not requiring a parser library
|
||||||
it('handles missing language', function()
|
it('handles missing language', function()
|
||||||
local path_pat = 'Error executing lua: '..(iswin() and '.+\\vim\\' or '.+/vim/')
|
eq('Error executing lua: .../treesitter.lua: no such language: borklang',
|
||||||
|
|
||||||
matches(path_pat..'treesitter.lua:39: no such language: borklang',
|
|
||||||
pcall_err(exec_lua, "parser = vim.treesitter.create_parser(0, 'borklang')"))
|
pcall_err(exec_lua, "parser = vim.treesitter.create_parser(0, 'borklang')"))
|
||||||
|
|
||||||
-- actual message depends on platform
|
-- actual message depends on platform
|
||||||
|
|
|
@ -10,7 +10,6 @@ local feed = helpers.feed
|
||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local matches = helpers.matches
|
local matches = helpers.matches
|
||||||
local iswin = helpers.iswin
|
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
|
@ -148,9 +147,11 @@ describe('lua stdlib', function()
|
||||||
]])
|
]])
|
||||||
eq({"yy","xx"}, exec_lua("return test_table"))
|
eq({"yy","xx"}, exec_lua("return test_table"))
|
||||||
|
|
||||||
-- type checked args
|
-- Validates args.
|
||||||
eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule('stringly')"))
|
eq('Error executing lua: vim.schedule: expected function',
|
||||||
eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule()"))
|
pcall_err(exec_lua, "vim.schedule('stringly')"))
|
||||||
|
eq('Error executing lua: vim.schedule: expected function',
|
||||||
|
pcall_err(exec_lua, "vim.schedule()"))
|
||||||
|
|
||||||
exec_lua([[
|
exec_lua([[
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
@ -223,12 +224,14 @@ describe('lua stdlib', function()
|
||||||
matches(".*Infinite loop detected", pcall_err(split, t[1], t[2]))
|
matches(".*Infinite loop detected", pcall_err(split, t[1], t[2]))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- type checked args
|
-- Validates args.
|
||||||
eq(true, pcall(split, 'string', 'string', nil))
|
eq(true, pcall(split, 'string', 'string', nil))
|
||||||
local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:'
|
eq('Error executing lua: .../shared.lua: Expected string, got number',
|
||||||
matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 1, 'string', nil))
|
pcall_err(split, 1, 'string', nil))
|
||||||
matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 'string', 1, nil))
|
eq('Error executing lua: .../shared.lua: Expected string, got number',
|
||||||
matches("Error executing lua: "..path_pattern.." Expected boolean or nil, got number", pcall_err(split, 'string', 'string', 1))
|
pcall_err(split, 'string', 1, nil))
|
||||||
|
eq('Error executing lua: .../shared.lua: Expected boolean or nil, got number',
|
||||||
|
pcall_err(split, 'string', 'string', 1))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('vim.trim', function()
|
it('vim.trim', function()
|
||||||
|
@ -247,9 +250,9 @@ describe('lua stdlib', function()
|
||||||
assert(t[2], trim(t[1]))
|
assert(t[2], trim(t[1]))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- type checked args
|
-- Validates args.
|
||||||
local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:'
|
eq('Error executing lua: .../shared.lua: Expected string, got number',
|
||||||
matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(trim, 2))
|
pcall_err(trim, 2))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('vim.inspect', function()
|
it('vim.inspect', function()
|
||||||
|
@ -289,15 +292,11 @@ describe('lua stdlib', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('vim.pesc', function()
|
it('vim.pesc', function()
|
||||||
local pesc = function(s)
|
eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]]))
|
||||||
return exec_lua('return vim.pesc(...)', s)
|
eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]]))
|
||||||
end
|
|
||||||
|
|
||||||
eq('foo%-bar', pesc('foo-bar'))
|
-- Validates args.
|
||||||
eq('foo%%%-bar', pesc(pesc('foo-bar')))
|
eq("Error executing lua: .../shared.lua: Expected string, got number",
|
||||||
|
pcall_err(exec_lua, [[return vim.pesc(2)]]))
|
||||||
-- type checked args
|
|
||||||
local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:'
|
|
||||||
matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(pesc, 2))
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -74,7 +74,8 @@ function module.matches(pat, actual)
|
||||||
error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual))
|
error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Invokes `fn` and returns the error string, or raises an error if `fn` succeeds.
|
-- Invokes `fn` and returns the error string (may truncate full paths), or
|
||||||
|
-- raises an error if `fn` succeeds.
|
||||||
--
|
--
|
||||||
-- Usage:
|
-- Usage:
|
||||||
-- -- Match exact string.
|
-- -- Match exact string.
|
||||||
|
@ -88,7 +89,17 @@ function module.pcall_err(fn, ...)
|
||||||
if status == true then
|
if status == true then
|
||||||
error('expected failure, but got success')
|
error('expected failure, but got success')
|
||||||
end
|
end
|
||||||
|
-- From this:
|
||||||
|
-- /home/foo/neovim/runtime/lua/vim/shared.lua:186: Expected string, got number
|
||||||
|
-- to this:
|
||||||
|
-- Expected string, got number
|
||||||
local errmsg = tostring(rv):gsub('^[^:]+:%d+: ', '')
|
local errmsg = tostring(rv):gsub('^[^:]+:%d+: ', '')
|
||||||
|
-- From this:
|
||||||
|
-- Error executing lua: /very/long/foo.lua:186: Expected string, got number
|
||||||
|
-- to this:
|
||||||
|
-- Error executing lua: .../foo.lua:186: Expected string, got number
|
||||||
|
errmsg = errmsg:gsub([[lua: [a-zA-Z]?:?[^:]-[/\]([^:/\]+):%d+: ]], 'lua: .../%1: ')
|
||||||
|
-- ^ Windows drive-letter (C:)
|
||||||
return errmsg
|
return errmsg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue