aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/node_spec.lua
diff options
context:
space:
mode:
authorQuentin Rasmont <qrasmont@gmail.com>2022-05-01 11:35:12 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-25 18:01:14 +0200
commitbaba43681e792db30318bdedc3e73e4fe12482a6 (patch)
tree4ac5218831574e3070ac1af42251b49afdebf749 /test/functional/treesitter/node_spec.lua
parenta577fb778addb6eb305ade82a229b52673ced234 (diff)
downloadrneovim-baba43681e792db30318bdedc3e73e4fe12482a6.tar.gz
rneovim-baba43681e792db30318bdedc3e73e4fe12482a6.tar.bz2
rneovim-baba43681e792db30318bdedc3e73e4fe12482a6.zip
feat(treesitter): upstream get_root_for_node() 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.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index b9ad4925c9..9450526257 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -77,4 +77,19 @@ describe('treesitter node API', function()
eq(3, len)
eq('<node compound_statement>', lua_eval('tostring(children[3])'))
end)
+
+ it('can retrieve the tree root given a node', function()
+ insert([[
+ int main() {
+ int x = 3;
+ }]])
+
+ exec_lua([[
+ tree = vim.treesitter.get_parser(0, "c"):parse()[1]
+ root = tree:root()
+ node = root:child(0):child(2)
+ ]])
+
+ eq(lua_eval('tostring(root)'), lua_eval('tostring(node:root())'))
+ end)
end)