From a577fb778addb6eb305ade82a229b52673ced234 Mon Sep 17 00:00:00 2001 From: Quentin Rasmont Date: Sat, 30 Apr 2022 20:54:25 +0200 Subject: feat(treesitter): upstream get_named_children() as a node method Util from the nvim-treesitter project. --- test/functional/treesitter/node_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/treesitter/node_spec.lua') 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('', lua_eval('tostring(children[3])')) + end) end) -- cgit From baba43681e792db30318bdedc3e73e4fe12482a6 Mon Sep 17 00:00:00 2001 From: Quentin Rasmont Date: Sun, 1 May 2022 11:35:12 +0200 Subject: feat(treesitter): upstream get_root_for_node() as a node method Util from the nvim-treesitter project. --- test/functional/treesitter/node_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/treesitter/node_spec.lua') 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('', 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) -- cgit From f57341a4b69398ff0c58686e66c2f4138be164aa Mon Sep 17 00:00:00 2001 From: Quentin Rasmont Date: Sun, 1 May 2022 21:13:47 +0200 Subject: feat(treesitter): upstream node_length() as a node method Util from the nvim-treesitter project. --- test/functional/treesitter/node_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 9450526257..87ce1b973c 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -92,4 +92,20 @@ describe('treesitter node API', function() eq(lua_eval('tostring(root)'), lua_eval('tostring(node:root())')) end) + + it('can compute the byte length of a node', function() + insert([[ + int main() { + int x = 3; + }]]) + + exec_lua([[ + tree = vim.treesitter.get_parser(0, "c"):parse()[1] + root = tree:root() + child = root:child(0):child(0) + ]]) + + eq(28, lua_eval('root:byte_length()')) + eq(3, lua_eval('child:byte_length()')) + end) end) -- cgit From 6254b0fd3bc725705020192dc9e35635136b9929 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 16:13:37 +0200 Subject: ci(tests): don't skip parsers on functionaltest Treesitter parsers are now a mandatory part of the installation and should be tested on all platforms. Remove `pending_c_parser` helper. --- test/functional/treesitter/node_spec.lua | 5 ----- 1 file changed, 5 deletions(-) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 87ce1b973c..a82dce47b7 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -4,7 +4,6 @@ local clear = helpers.clear local eq = helpers.eq local exec_lua = helpers.exec_lua local insert = helpers.insert -local pending_c_parser = helpers.pending_c_parser before_each(clear) @@ -15,10 +14,6 @@ end describe('treesitter node API', function() clear() - if pending_c_parser(pending) then - return - end - it('can move between siblings', function() insert([[ int main(int x, int y, int z) { -- cgit