aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/node_spec.lua
diff options
context:
space:
mode:
authorQuentin Rasmont <qrasmont@gmail.com>2022-04-30 20:54:25 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-25 18:01:14 +0200
commita577fb778addb6eb305ade82a229b52673ced234 (patch)
treefe28abc6010ee73753e97aace4c41648fcae6d0a /test/functional/treesitter/node_spec.lua
parent6b2d42eb0352d01923e4bf2e3ce0824c662b7be4 (diff)
downloadrneovim-a577fb778addb6eb305ade82a229b52673ced234.tar.gz
rneovim-a577fb778addb6eb305ade82a229b52673ced234.tar.bz2
rneovim-a577fb778addb6eb305ade82a229b52673ced234.zip
feat(treesitter): upstream get_named_children() as a node method
Util from the nvim-treesitter project.
Diffstat (limited to 'test/functional/treesitter/node_spec.lua')
-rw-r--r--test/functional/treesitter/node_spec.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index 21c287644e..b9ad4925c9 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -59,4 +59,22 @@ describe('treesitter node API', function()
exec_lua 'node = node:prev_named_sibling()'
eq('int x', lua_eval('node_text(node)'))
end)
+
+ it('can retrieve the children of a node', function()
+ insert([[
+ int main() {
+ int x = 3;
+ }]])
+
+ local len = exec_lua([[
+ tree = vim.treesitter.get_parser(0, "c"):parse()[1]
+ node = tree:root():child(0)
+ children = node:named_children()
+
+ return #children
+ ]])
+
+ eq(3, len)
+ eq('<node compound_statement>', lua_eval('tostring(children[3])'))
+ end)
end)