aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/treesitter_spec.lua
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-06-17 21:46:31 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2019-09-28 14:55:43 +0200
commit167a1cfdef0c4b3526830ad0356f06bf480df6af (patch)
tree8fcca0990c2048627c48ca89d6a9208de7374b76 /test/functional/lua/treesitter_spec.lua
parentd697841a9d3030efaf10dbddaee9f3c0a8fe1b78 (diff)
downloadrneovim-167a1cfdef0c4b3526830ad0356f06bf480df6af.tar.gz
rneovim-167a1cfdef0c4b3526830ad0356f06bf480df6af.tar.bz2
rneovim-167a1cfdef0c4b3526830ad0356f06bf480df6af.zip
tree-sitter: improve parser API (shared parser between plugins)
Diffstat (limited to 'test/functional/lua/treesitter_spec.lua')
-rw-r--r--test/functional/lua/treesitter_spec.lua27
1 files changed, 24 insertions, 3 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index 8916e59563..f3f7f4fd0a 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -8,6 +8,7 @@ local insert = helpers.insert
local meth_pcall = helpers.meth_pcall
local exec_lua = helpers.exec_lua
local iswin = helpers.iswin
+local feed = helpers.feed
before_each(clear)
@@ -46,12 +47,11 @@ describe('tree-sitter API', function()
}]])
exec_lua([[
- parser = vim.treesitter.create_parser(0, "c")
- tree = parser:parse_tree()
+ parser = vim.treesitter.get_parser(0, "c")
+ tree = parser:parse()
root = tree:root()
]])
- --eq("<parser>", exec_lua("return tostring(parser)"))
eq("<tree>", exec_lua("return tostring(tree)"))
eq("<node translation_unit>", exec_lua("return tostring(root)"))
eq({0,0,3,0}, exec_lua("return {root:range()}"))
@@ -60,6 +60,27 @@ describe('tree-sitter API', function()
exec_lua("child = root:child(0)")
eq("<node function_definition>", exec_lua("return tostring(child)"))
eq({0,0,2,1}, exec_lua("return {child:range()}"))
+
+ exec_lua("descendant = root:descendant_for_point_range(1,2,1,12)")
+ eq("<node declaration>", exec_lua("return tostring(descendant)"))
+ eq({1,2,1,12}, exec_lua("return {descendant:range()}"))
+ eq("(declaration (primitive_type) (init_declarator (identifier) (number_literal)))", exec_lua("return descendant:sexpr()"))
+
+ feed("2G7|ay")
+ exec_lua([[
+ tree2 = parser:parse()
+ root2 = tree2:root()
+ descendant2 = root2:descendant_for_point_range(1,2,1,13)
+ ]])
+ eq(false, exec_lua("return tree2 == tree1"))
+ eq("<node declaration>", exec_lua("return tostring(descendant2)"))
+ eq({1,2,1,13}, exec_lua("return {descendant2:range()}"))
+
+ -- orginal tree did not change
+ eq({1,2,1,12}, exec_lua("return {descendant:range()}"))
+
+ -- unchanged buffer: return the same tree
+ eq(true, exec_lua("return parser:parse() == tree2"))
end)
end)