aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/lua/overrides_spec.lua6
-rw-r--r--test/functional/treesitter/parser_spec.lua40
-rw-r--r--test/helpers.lua8
3 files changed, 50 insertions, 4 deletions
diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua
index 1777dd078d..c08f3d06a9 100644
--- a/test/functional/lua/overrides_spec.lua
+++ b/test/functional/lua/overrides_spec.lua
@@ -54,7 +54,7 @@ describe('print', function()
-- TODO(bfredl): these look weird, print() should not use "E5114:" style errors..
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]',
pcall_err(command, 'lua print("foo", v_nilerr, "bar")'))
- eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:0: abc',
+ eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc',
pcall_err(command, 'lua print("foo", v_abcerr, "bar")'))
eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',
pcall_err(command, 'lua print("foo", v_tblout, "bar")'))
@@ -84,9 +84,9 @@ describe('print', function()
end
]])
eq('', exec_capture('luafile ' .. fname))
- eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: my mistake',
+ eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake',
pcall_err(command, 'lua string_error()'))
- eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:0: 1234',
+ eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234',
pcall_err(command, 'lua number_error()'))
eq('Vim(lua):E5108: Error executing lua [NULL]',
pcall_err(command, 'lua nil_error()'))
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index 56af0c8738..37dde37a64 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -1055,4 +1055,44 @@ int x = INT_MAX;
]])
end)
+ it('fails to load queries', function()
+ local function test(exp, cquery)
+ eq(exp, pcall_err(exec_lua, "vim.treesitter.query.parse('c', ...)", cquery))
+ end
+
+ -- Invalid node type
+ test(
+ '.../query.lua:0: Query error at 1:2. Invalid node type "dentifier":\n'..
+ '(dentifier) @variable\n'..
+ ' ^',
+ '(dentifier) @variable')
+
+ -- Impossible pattern
+ test(
+ '.../query.lua:0: Query error at 1:13. Impossible pattern:\n'..
+ '(identifier (identifier) @variable)\n'..
+ ' ^',
+ '(identifier (identifier) @variable)')
+
+ -- Invalid syntax
+ test(
+ '.../query.lua:0: Query error at 1:13. Invalid syntax:\n'..
+ '(identifier @variable\n'..
+ ' ^',
+ '(identifier @variable')
+
+ -- Invalid field name
+ test(
+ '.../query.lua:0: Query error at 1:15. Invalid field name "invalid_field":\n'..
+ '((identifier) invalid_field: (identifier))\n'..
+ ' ^',
+ '((identifier) invalid_field: (identifier))')
+
+ -- Invalid capture name
+ test(
+ '.../query.lua:0: Query error at 1:30. Invalid capture name "ok.capture":\n'..
+ '((identifier) @id (#eq? @id @ok.capture))\n'..
+ ' ^',
+ '((identifier) @id (#eq? @id @ok.capture))')
+ end)
end)
diff --git a/test/helpers.lua b/test/helpers.lua
index 51114611ab..02192e4924 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -188,10 +188,16 @@ function module.pcall(fn, ...)
local errmsg = tostring(rv):gsub('([%s<])vim[/\\]([^%s:/\\]+):%d+', '%1\xffvim\xff%2:0')
:gsub('[^%s<]-[/\\]([^%s:/\\]+):%d+', '.../%1:0')
:gsub('\xffvim\xff', 'vim/')
+
-- Scrub numbers in paths/stacktraces:
-- shared.lua:0: in function 'gsplit'
-- shared.lua:0: in function <shared.lua:0>'
- errmsg = errmsg:gsub('([^%s]):%d+', '%1:0')
+ errmsg = errmsg:gsub('([^%s].lua):%d+', '%1:0')
+ -- [string "<nvim>"]:0:
+ -- [string ":lua"]:0:
+ -- [string ":luado"]:0:
+ errmsg = errmsg:gsub('(%[string "[^"]+"%]):%d+', '%1:0')
+
-- Scrub tab chars:
errmsg = errmsg:gsub('\t', ' ')
-- In Lua 5.1, we sometimes get a "(tail call): ?" on the last line.