feat(treesitter): upstream node_length() as a node method

Util from the nvim-treesitter project.
This commit is contained in:
Quentin Rasmont
2022-05-01 21:13:47 +02:00
committed by bfredl
parent baba43681e
commit f57341a4b6
2 changed files with 31 additions and 0 deletions

View File

@@ -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)