mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
feat(treesitter): upstream is_parent()
Util from the nvim-treesitter project. Renamed is_parent to is_ancestor for clarity.
This commit is contained in:
29
test/functional/treesitter/utils_spec.lua
Normal file
29
test/functional/treesitter/utils_spec.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
|
||||
local clear = helpers.clear
|
||||
local insert = helpers.insert
|
||||
local eq = helpers.eq
|
||||
local exec_lua = helpers.exec_lua
|
||||
|
||||
before_each(clear)
|
||||
|
||||
describe('treesitter utils', function()
|
||||
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)
|
||||
end)
|
||||
Reference in New Issue
Block a user