diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-10-02 10:34:14 -0700 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2024-10-11 17:29:45 +0200 |
commit | 267c7525f738cdd6024c39da758e885c026ffaaa (patch) | |
tree | 869fcb5fa87b4f9b2c4f0a0295498c5ed2883b73 /test/functional/treesitter/node_spec.lua | |
parent | c4762b309714897615607f135aab9d7bcc763c4f (diff) | |
download | rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.tar.gz rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.tar.bz2 rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.zip |
feat(treesitter): introduce child_with_descendant()
This commit also marks `child_containing_descendant()` as deprecated
(per upstream's documentation), and uses `child_with_descendant()` in
its place. Minimum required tree-sitter version will now be `0.24`.
Diffstat (limited to 'test/functional/treesitter/node_spec.lua')
-rw-r--r-- | test/functional/treesitter/node_spec.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index d07ed35368..c87a56b160 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -186,4 +186,28 @@ describe('treesitter node API', function() ) eq(vim.NIL, lua_eval('declarator:child_containing_descendant(value)')) end) + + it('child_with_descendant() works', function() + insert([[ + int main() { + int x = 3; + }]]) + + exec_lua(function() + local tree = vim.treesitter.get_parser(0, 'c'):parse()[1] + _G.root = assert(tree:root()) + _G.main = assert(_G.root:child(0)) + _G.body = assert(_G.main:child(2)) + _G.statement = assert(_G.body:child(1)) + _G.declarator = assert(_G.statement:child(1)) + _G.value = assert(_G.declarator:child(1)) + end) + + eq(lua_eval('main:type()'), lua_eval('root:child_with_descendant(value):type()')) + eq(lua_eval('body:type()'), lua_eval('main:child_with_descendant(value):type()')) + eq(lua_eval('statement:type()'), lua_eval('body:child_with_descendant(value):type()')) + eq(lua_eval('declarator:type()'), lua_eval('statement:child_with_descendant(value):type()')) + eq(lua_eval('value:type()'), lua_eval('declarator:child_with_descendant(value):type()')) + eq(vim.NIL, lua_eval('value:child_with_descendant(value)')) + end) end) |