diff options
author | Quentin Rasmont <qrasmont@gmail.com> | 2022-04-22 21:50:52 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-08-25 18:01:14 +0200 |
commit | 3aba4ba37859e4407eff2bb3f4d99c44b108ed79 (patch) | |
tree | b64398bebd9f5f2860249056eef84016e250ca58 /test/functional/treesitter/utils_spec.lua | |
parent | 22f920030214c0023525c59daf763441baddba1a (diff) | |
download | rneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.tar.gz rneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.tar.bz2 rneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.zip |
feat(treesitter): upstream is_parent()
Util from the nvim-treesitter project.
Renamed is_parent to is_ancestor for clarity.
Diffstat (limited to 'test/functional/treesitter/utils_spec.lua')
-rw-r--r-- | test/functional/treesitter/utils_spec.lua | 29 |
1 files changed, 29 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..c5609501a7 --- /dev/null +++ b/test/functional/treesitter/utils_spec.lua @@ -0,0 +1,29 @@ +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 + +before_each(clear) + +describe('treesitter utils', function() + clear() + it('can find an ancestor', function() + 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) |