aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2025-02-15 13:33:38 -0800
committerLewis Russell <me@lewisr.dev>2025-02-21 09:47:02 +0000
commit55b165ac15a7528a3c679d928b1edf9d701f850b (patch)
tree17c86f717b79a42e87cd9c58a031b0aff0a755f2 /test
parent3e39250a79ef1a74bd64e283daf825208ca3875b (diff)
downloadrneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.tar.gz
rneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.tar.bz2
rneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.zip
fix(treesitter): `TSNode:field()` returns all children with the given field
Diffstat (limited to 'test')
-rw-r--r--test/functional/treesitter/node_spec.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index 235bf7861c..2a1fa497af 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -186,4 +186,23 @@ describe('treesitter node API', function()
eq(lua_eval('value:type()'), lua_eval('declarator:child_with_descendant(value):type()'))
eq(vim.NIL, lua_eval('value:child_with_descendant(value)'))
end)
+
+ it('gets all children with a given field name', function()
+ insert([[
+ function foo(a,b,c)
+ end
+ ]])
+
+ exec_lua(function()
+ local tree = vim.treesitter.get_parser(0, 'lua'):parse()[1]
+ _G.parameters_node = assert(tree:root():named_descendant_for_range(0, 18, 0, 18))
+ _G.children_by_field = _G.parameters_node:field('name')
+ end)
+
+ eq('parameters', lua_eval('parameters_node:type()'))
+ eq(3, lua_eval('#children_by_field'))
+ eq('a', lua_eval('vim.treesitter.get_node_text(children_by_field[1], 0)'))
+ eq('b', lua_eval('vim.treesitter.get_node_text(children_by_field[2], 0)'))
+ eq('c', lua_eval('vim.treesitter.get_node_text(children_by_field[3], 0)'))
+ end)
end)