aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2021-08-23 09:14:40 +0200
committerGitHub <noreply@github.com>2021-08-23 09:14:40 +0200
commit34b60ec894dd0c7347c13916c71c48404dd76421 (patch)
tree773e9dc883b012f1abc8b692f182afc5ffc83500 /test
parent4b3ffde20856bd9da8386317490bb1a9fbf34b3a (diff)
parent140084180e82bea3afafa32a33fee37e6e9473ca (diff)
downloadrneovim-34b60ec894dd0c7347c13916c71c48404dd76421.tar.gz
rneovim-34b60ec894dd0c7347c13916c71c48404dd76421.tar.bz2
rneovim-34b60ec894dd0c7347c13916c71c48404dd76421.zip
Merge pull request #15434 from Dkendal/feature-lua-treesitter-sibling
feat(treesitter): add next, prev sibling method
Diffstat (limited to 'test')
-rw-r--r--test/functional/treesitter/node_spec.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua
new file mode 100644
index 0000000000..21c287644e
--- /dev/null
+++ b/test/functional/treesitter/node_spec.lua
@@ -0,0 +1,62 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local insert = helpers.insert
+local pending_c_parser = helpers.pending_c_parser
+
+before_each(clear)
+
+local function lua_eval(lua_expr)
+ return exec_lua("return " .. lua_expr)
+end
+
+describe('treesitter node API', function()
+ clear()
+
+ if pending_c_parser(pending) then
+ return
+ end
+
+ it('can move between siblings', function()
+ insert([[
+ int main(int x, int y, int z) {
+ return x + y * z
+ }
+ ]])
+
+ exec_lua([[
+ query = require"vim.treesitter.query"
+ parser = vim.treesitter.get_parser(0, "c")
+ tree = parser:parse()[1]
+ root = tree:root()
+ lang = vim.treesitter.inspect_language('c')
+
+ function node_text(node)
+ return query.get_node_text(node, 0)
+ end
+ ]])
+
+ exec_lua 'node = root:descendant_for_range(0, 11, 0, 16)'
+ eq('int x', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:next_sibling()'
+ eq(',', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:next_sibling()'
+ eq('int y', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:prev_sibling()'
+ eq(',', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:prev_sibling()'
+ eq('int x', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:next_named_sibling()'
+ eq('int y', lua_eval('node_text(node)'))
+
+ exec_lua 'node = node:prev_named_sibling()'
+ eq('int x', lua_eval('node_text(node)'))
+ end)
+end)