diff options
Diffstat (limited to 'test/functional/treesitter/node_spec.lua')
-rw-r--r-- | test/functional/treesitter/node_spec.lua | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index f114d36823..96579f296b 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -1,10 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local assert_alive = helpers.assert_alive +local clear = n.clear +local eq = t.eq +local exec_lua = n.exec_lua +local insert = n.insert +local assert_alive = n.assert_alive before_each(clear) @@ -142,4 +143,30 @@ describe('treesitter node API', function() eq(28, lua_eval('root:byte_length()')) eq(3, lua_eval('child:byte_length()')) end) + + it('child_containing_descendant() works', function() + insert([[ + int main() { + int x = 3; + }]]) + + exec_lua([[ + tree = vim.treesitter.get_parser(0, "c"):parse()[1] + root = tree:root() + main = root:child(0) + body = main:child(2) + statement = body:child(1) + declarator = statement:child(1) + value = declarator:child(1) + ]]) + + eq(lua_eval('main:type()'), lua_eval('root:child_containing_descendant(value):type()')) + eq(lua_eval('body:type()'), lua_eval('main:child_containing_descendant(value):type()')) + eq(lua_eval('statement:type()'), lua_eval('body:child_containing_descendant(value):type()')) + eq( + lua_eval('declarator:type()'), + lua_eval('statement:child_containing_descendant(value):type()') + ) + eq(vim.NIL, lua_eval('declarator:child_containing_descendant(value)')) + end) end) |