test: support upvalues in exec_lua

This commit is contained in:
Lewis Russell
2024-08-11 09:27:48 +01:00
committed by Lewis Russell
parent a19e89022d
commit e5c174421d
34 changed files with 1740 additions and 1362 deletions

View File

@@ -660,8 +660,8 @@ print()
end)
local function run_query()
return exec_lua(function(query_str)
local query = vim.treesitter.query.parse('c', query_str)
return exec_lua(function()
local query = vim.treesitter.query.parse('c', query0)
local parser = vim.treesitter.get_parser()
local tree = parser:parse()[1]
local res = {}
@@ -669,7 +669,7 @@ print()
table.insert(res, { query.captures[id], node:range() })
end
return res
end, query0)
end)
end
eq({
@@ -707,15 +707,15 @@ print()
]]
]==]
local r = exec_lua(function(src)
local parser = vim.treesitter.get_string_parser(src, 'lua')
local r = exec_lua(function()
local parser = vim.treesitter.get_string_parser(source, 'lua')
parser:parse(true)
local ranges = {}
parser:for_each_tree(function(tstree, tree)
ranges[tree:lang()] = { tstree:root():range(true) }
end)
return ranges
end, source)
end)
eq({
lua = { 0, 6, 6, 16, 4, 438 },
@@ -727,14 +727,14 @@ print()
-- the ranges but only provide a Range4. Strip the byte entries from the ranges and make sure
-- add_bytes() produces the same result.
local rb = exec_lua(function(r0, source0)
local rb = exec_lua(function()
local add_bytes = require('vim.treesitter._range').add_bytes
for lang, range in pairs(r0) do
r0[lang] = { range[1], range[2], range[4], range[5] }
r0[lang] = add_bytes(source0, r0[lang])
for lang, range in pairs(r) do
r[lang] = { range[1], range[2], range[4], range[5] }
r[lang] = add_bytes(source, r[lang])
end
return r0
end, r, source)
return r
end)
eq(rb, r)
end)