diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/treesitter/node_spec.lua | 24 | ||||
-rw-r--r-- | test/functional/treesitter/query_spec.lua | 14 |
2 files changed, 38 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) diff --git a/test/functional/treesitter/query_spec.lua b/test/functional/treesitter/query_spec.lua index c97619c913..dfb5eb2685 100644 --- a/test/functional/treesitter/query_spec.lua +++ b/test/functional/treesitter/query_spec.lua @@ -405,6 +405,20 @@ void ui_refresh(void) { 'literal', 'number_literal', { 0, 8, 0, 11 }, '123' }, { 'literal', 'number_literal', { 2, 21, 2, 24 }, '125' }, }, result) + + result = exec_lua( + get_query_result, + [[((number_literal) @literal (#has-ancestor? @literal "enumerator"))]] + ) + eq({ + { 'literal', 'number_literal', { 1, 13, 1, 16 }, '124' }, + }, result) + + result = exec_lua( + get_query_result, + [[((number_literal) @literal (#has-ancestor? @literal "number_literal"))]] + ) + eq({}, result) end) it('allows loading query with escaped quotes and capture them `#{lua,vim}-match`?', function() |