mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 19:25:11 -07:00
48 lines
1.1 KiB
Lua
48 lines
1.1 KiB
Lua
local t = require('test.functional.testutil')()
|
|
|
|
local clear = t.clear
|
|
local insert = t.insert
|
|
local eq = t.eq
|
|
local exec_lua = t.exec_lua
|
|
|
|
before_each(clear)
|
|
|
|
describe('treesitter utils', function()
|
|
before_each(clear)
|
|
|
|
it('can find an ancestor', function()
|
|
insert([[
|
|
int main() {
|
|
int x = 3;
|
|
}]])
|
|
|
|
exec_lua([[
|
|
parser = vim.treesitter.get_parser(0, "c")
|
|
tree = parser:parse()[1]
|
|
root = tree:root()
|
|
ancestor = root:child(0)
|
|
child = ancestor:child(0)
|
|
]])
|
|
|
|
eq(true, exec_lua('return vim.treesitter.is_ancestor(ancestor, child)'))
|
|
eq(false, exec_lua('return vim.treesitter.is_ancestor(child, ancestor)'))
|
|
end)
|
|
|
|
it('can detect if a position is contained in a node', function()
|
|
exec_lua([[
|
|
node = {
|
|
range = function()
|
|
return 0, 4, 0, 8
|
|
end,
|
|
}
|
|
]])
|
|
|
|
eq(false, exec_lua('return vim.treesitter.is_in_node_range(node, 0, 3)'))
|
|
for i = 4, 7 do
|
|
eq(true, exec_lua('return vim.treesitter.is_in_node_range(node, 0, ...)', i))
|
|
end
|
|
-- End column exclusive
|
|
eq(false, exec_lua('return vim.treesitter.is_in_node_range(node, 0, 8)'))
|
|
end)
|
|
end)
|