aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/utils_spec.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-08-25 21:35:13 +0200
committerGitHub <noreply@github.com>2022-08-25 21:35:13 +0200
commitbfd1adc62c615e7b65bdfe6d3c21158708eb4314 (patch)
treeec839f0bb6d5c28780f9e694aa2bf764871382b3 /test/functional/treesitter/utils_spec.lua
parent22f920030214c0023525c59daf763441baddba1a (diff)
parent73ee2b35d1fc738be9bd4b99f49ce8f84351fbe6 (diff)
downloadrneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.tar.gz
rneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.tar.bz2
rneovim-bfd1adc62c615e7b65bdfe6d3c21158708eb4314.zip
Merge pull request #19946 from bfredl/newnode
feat: upstream some nvim-treesitter functions
Diffstat (limited to 'test/functional/treesitter/utils_spec.lua')
-rw-r--r--test/functional/treesitter/utils_spec.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/functional/treesitter/utils_spec.lua b/test/functional/treesitter/utils_spec.lua
new file mode 100644
index 0000000000..4f4c18a748
--- /dev/null
+++ b/test/functional/treesitter/utils_spec.lua
@@ -0,0 +1,33 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local insert = helpers.insert
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local pending_c_parser = helpers.pending_c_parser
+
+before_each(clear)
+
+describe('treesitter utils', function()
+ before_each(clear)
+
+ it('can find an ancestor', function()
+ if pending_c_parser(pending) then return end
+
+ insert([[
+ int main() {
+ int x = 3;
+ }]])
+
+ exec_lua([[
+ parser = vim.treesitter.get_parser(0, "c")
+ tree = parser:parse()[1]
+ root = tree:root()
+ ancestor = root:child(0)
+ child = ancestor:child(0)
+ ]])
+
+ eq(true, exec_lua('return vim.treesitter.is_ancestor(ancestor, child)'))
+ eq(false, exec_lua('return vim.treesitter.is_ancestor(child, ancestor)'))
+ end)
+end)