aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/node_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/treesitter/node_spec.lua')
-rw-r--r--test/functional/treesitter/node_spec.lua19
1 files changed, 16 insertions, 3 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
index eef75d0e91..f114d36823 100644
--- a/test/functional/treesitter/node_spec.lua
+++ b/test/functional/treesitter/node_spec.lua
@@ -9,7 +9,7 @@ local assert_alive = helpers.assert_alive
before_each(clear)
local function lua_eval(lua_expr)
- return exec_lua("return " .. lua_expr)
+ return exec_lua('return ' .. lua_expr)
end
describe('treesitter node API', function()
@@ -40,6 +40,20 @@ describe('treesitter node API', function()
assert_alive()
end)
+ it('get_node() with lang given', function()
+ -- this buffer doesn't have filetype set!
+ insert('local foo = function() end')
+ exec_lua([[
+ node = vim.treesitter.get_node({
+ bufnr = 0,
+ pos = { 0, 6 }, -- on "foo"
+ lang = 'lua',
+ })
+ ]])
+ eq('foo', lua_eval('vim.treesitter.get_node_text(node, 0)'))
+ eq('identifier', lua_eval('node:type()'))
+ end)
+
it('can move between siblings', function()
insert([[
int main(int x, int y, int z) {
@@ -48,14 +62,13 @@ describe('treesitter node API', function()
]])
exec_lua([[
- query = require"vim.treesitter.query"
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()[1]
root = tree:root()
lang = vim.treesitter.language.inspect('c')
function node_text(node)
- return query.get_node_text(node, 0)
+ return vim.treesitter.get_node_text(node, 0)
end
]])