aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/inspect_tree_spec.lua
diff options
context:
space:
mode:
authorJongwook Choi <wookayin@gmail.com>2024-02-01 15:25:40 -0500
committerJongwook Choi <wookayin@gmail.com>2024-02-05 16:23:22 -0500
commitf4a3c326314b079e660ebd0f3c837f69d8c425fc (patch)
treeedf00a49cb36b7980ba3f6378d6051d8670161dc /test/functional/treesitter/inspect_tree_spec.lua
parenta478bf936b2a648312704c02898eb7e5bfbf5692 (diff)
downloadrneovim-f4a3c326314b079e660ebd0f3c837f69d8c425fc.tar.gz
rneovim-f4a3c326314b079e660ebd0f3c837f69d8c425fc.tar.bz2
rneovim-f4a3c326314b079e660ebd0f3c837f69d8c425fc.zip
test(treesitter): add test cases for inspect_tree
Co-authored-by: altermo <107814000+altermo@users.noreply.github.com>
Diffstat (limited to 'test/functional/treesitter/inspect_tree_spec.lua')
-rw-r--r--test/functional/treesitter/inspect_tree_spec.lua109
1 files changed, 109 insertions, 0 deletions
diff --git a/test/functional/treesitter/inspect_tree_spec.lua b/test/functional/treesitter/inspect_tree_spec.lua
new file mode 100644
index 0000000000..0102838b82
--- /dev/null
+++ b/test/functional/treesitter/inspect_tree_spec.lua
@@ -0,0 +1,109 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local insert = helpers.insert
+local dedent = helpers.dedent
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+local feed = helpers.feed
+
+describe('vim.treesitter.inspect_tree', function()
+ before_each(clear)
+
+ local expect_tree = function(x)
+ local expected = vim.split(vim.trim(dedent(x)), '\n')
+ local actual = helpers.buf_lines(0) ---@type string[]
+ eq(expected, actual)
+ end
+
+ it('working', function()
+ insert([[
+ print()
+ ]])
+
+ exec_lua([[
+ vim.treesitter.start(0, 'lua')
+ vim.treesitter.inspect_tree()
+ ]])
+
+ expect_tree [[
+ (function_call ; [0, 0] - [0, 7]
+ name: (identifier) ; [0, 0] - [0, 5]
+ arguments: (arguments)) ; [0, 5] - [0, 7]
+ ]]
+ end)
+
+ it('can toggle to show anonymous nodes', function()
+ insert([[
+ print()
+ ]])
+
+ exec_lua([[
+ vim.treesitter.start(0, 'lua')
+ vim.treesitter.inspect_tree()
+ ]])
+ feed('a')
+
+ expect_tree [[
+ (function_call ; [0, 0] - [0, 7]
+ name: (identifier) ; [0, 0] - [0, 5]
+ arguments: (arguments ; [0, 5] - [0, 7]
+ "(" ; [0, 5] - [0, 6]
+ ")")) ; [0, 6] - [0, 7]
+ ]]
+ end)
+
+ it('works for injected trees', function()
+ insert([[
+ ```lua
+ return
+ ```
+ ]])
+
+ exec_lua([[
+ vim.treesitter.start(0, 'markdown')
+ vim.treesitter.get_parser():parse()
+ vim.treesitter.inspect_tree()
+ ]])
+
+ expect_tree [[
+ (section ; [0, 0] - [4, 0]
+ (fenced_code_block ; [0, 0] - [3, 0]
+ (fenced_code_block_delimiter) ; [0, 0] - [0, 3]
+ (info_string ; [0, 3] - [0, 6]
+ (language)) ; [0, 3] - [0, 6]
+ (block_continuation) ; [1, 0] - [1, 0]
+ (code_fence_content ; [1, 0] - [2, 0]
+ (return_statement) ; [1, 0] - [1, 6]
+ (block_continuation)) ; [2, 0] - [2, 0]
+ (fenced_code_block_delimiter))) ; [2, 0] - [2, 3]
+ ]]
+ end)
+
+ it('can toggle to show languages', function()
+ insert([[
+ ```lua
+ return
+ ```
+ ]])
+
+ exec_lua([[
+ vim.treesitter.start(0, 'markdown')
+ vim.treesitter.get_parser():parse()
+ vim.treesitter.inspect_tree()
+ ]])
+ feed('I')
+
+ expect_tree [[
+ (section ; [0, 0] - [4, 0] markdown
+ (fenced_code_block ; [0, 0] - [3, 0] markdown
+ (fenced_code_block_delimiter) ; [0, 0] - [0, 3] markdown
+ (info_string ; [0, 3] - [0, 6] markdown
+ (language)) ; [0, 3] - [0, 6] markdown
+ (block_continuation) ; [1, 0] - [1, 0] markdown
+ (code_fence_content ; [1, 0] - [2, 0] markdown
+ (return_statement) ; [1, 0] - [1, 6] lua
+ (block_continuation)) ; [2, 0] - [2, 0] markdown
+ (fenced_code_block_delimiter))) ; [2, 0] - [2, 3] markdown
+ ]]
+ end)
+end)