diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
commit | d5f194ce780c95821a855aca3c19426576d28ae0 (patch) | |
tree | d45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/treesitter/inspect_tree_spec.lua | |
parent | c5d770d311841ea5230426cc4c868e8db27300a8 (diff) | |
parent | 44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff) | |
download | rneovim-rahm.tar.gz rneovim-rahm.tar.bz2 rneovim-rahm.zip |
Diffstat (limited to 'test/functional/treesitter/inspect_tree_spec.lua')
-rw-r--r-- | test/functional/treesitter/inspect_tree_spec.lua | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/test/functional/treesitter/inspect_tree_spec.lua b/test/functional/treesitter/inspect_tree_spec.lua index 1f7d15cc96..68622140e4 100644 --- a/test/functional/treesitter/inspect_tree_spec.lua +++ b/test/functional/treesitter/inspect_tree_spec.lua @@ -120,14 +120,17 @@ describe('vim.treesitter.inspect_tree', function() end) it('updates source and tree buffer windows and closes them correctly', function() + local name = t.tmpname() + n.command('edit ' .. name) insert([[ print() ]]) + n.command('set filetype=lua | write') -- setup two windows for the source buffer exec_lua(function() _G.source_win = vim.api.nvim_get_current_win() - vim.api.nvim_open_win(0, false, { + _G.source_win2 = vim.api.nvim_open_win(0, false, { win = 0, split = 'left', }) @@ -135,40 +138,103 @@ describe('vim.treesitter.inspect_tree', function() -- setup three windows for the tree buffer exec_lua(function() - vim.treesitter.start(0, 'lua') vim.treesitter.inspect_tree() _G.tree_win = vim.api.nvim_get_current_win() - _G.tree_win_copy_1 = vim.api.nvim_open_win(0, false, { + _G.tree_win2 = vim.api.nvim_open_win(0, false, { win = 0, split = 'left', }) - _G.tree_win_copy_2 = vim.api.nvim_open_win(0, false, { + _G.tree_win3 = vim.api.nvim_open_win(0, false, { win = 0, split = 'left', }) end) - -- close original source window - exec_lua('vim.api.nvim_win_close(source_win, false)') + -- close original source window without closing tree views + exec_lua('vim.api.nvim_set_current_win(source_win)') + feed(':quit<CR>') + eq('', n.api.nvim_get_vvar('errmsg')) + eq(true, exec_lua('return vim.api.nvim_win_is_valid(tree_win)')) + eq(true, exec_lua('return vim.api.nvim_win_is_valid(tree_win2)')) + eq(true, exec_lua('return vim.api.nvim_win_is_valid(tree_win3)')) -- navigates correctly to the remaining source buffer window + exec_lua('vim.api.nvim_set_current_win(tree_win)') feed('<CR>') eq('', n.api.nvim_get_vvar('errmsg')) + eq(true, exec_lua('return vim.api.nvim_get_current_win() == source_win2')) -- close original tree window exec_lua(function() - vim.api.nvim_set_current_win(_G.tree_win_copy_1) + vim.api.nvim_set_current_win(_G.tree_win2) vim.api.nvim_win_close(_G.tree_win, false) end) -- navigates correctly to the remaining source buffer window feed('<CR>') eq('', n.api.nvim_get_vvar('errmsg')) + eq(true, exec_lua('return vim.api.nvim_get_current_win() == source_win2')) -- close source buffer window and all remaining tree windows - t.pcall_err(exec_lua, 'vim.api.nvim_win_close(0, false)') + n.expect_exit(n.command, 'quit') + end) - eq(false, exec_lua('return vim.api.nvim_win_is_valid(tree_win_copy_1)')) - eq(false, exec_lua('return vim.api.nvim_win_is_valid(tree_win_copy_2)')) + it('shows which nodes are missing', function() + insert([[ + int main() { + if (a.) { + // ^ MISSING field_identifier here + if (1) d() + // ^ MISSING ";" here + } + } + ]]) + + exec_lua(function() + vim.treesitter.start(0, 'c') + vim.treesitter.inspect_tree() + end) + feed('a') + + expect_tree [[ + (translation_unit ; [0, 0] - [8, 0] + (function_definition ; [0, 0] - [6, 1] + type: (primitive_type) ; [0, 0] - [0, 3] + declarator: (function_declarator ; [0, 4] - [0, 10] + declarator: (identifier) ; [0, 4] - [0, 8] + parameters: (parameter_list ; [0, 8] - [0, 10] + "(" ; [0, 8] - [0, 9] + ")")) ; [0, 9] - [0, 10] + body: (compound_statement ; [0, 11] - [6, 1] + "{" ; [0, 11] - [0, 12] + (if_statement ; [1, 4] - [5, 5] + "if" ; [1, 4] - [1, 6] + condition: (parenthesized_expression ; [1, 7] - [1, 11] + "(" ; [1, 7] - [1, 8] + (field_expression ; [1, 8] - [1, 10] + argument: (identifier) ; [1, 8] - [1, 9] + operator: "." ; [1, 9] - [1, 10] + field: (MISSING field_identifier)) ; [1, 10] - [1, 10] + ")") ; [1, 10] - [1, 11] + consequence: (compound_statement ; [1, 12] - [5, 5] + "{" ; [1, 12] - [1, 13] + (comment) ; [2, 4] - [2, 41] + (if_statement ; [3, 8] - [4, 36] + "if" ; [3, 8] - [3, 10] + condition: (parenthesized_expression ; [3, 11] - [3, 14] + "(" ; [3, 11] - [3, 12] + (number_literal) ; [3, 12] - [3, 13] + ")") ; [3, 13] - [3, 14] + consequence: (expression_statement ; [3, 15] - [4, 36] + (call_expression ; [3, 15] - [3, 18] + function: (identifier) ; [3, 15] - [3, 16] + arguments: (argument_list ; [3, 16] - [3, 18] + "(" ; [3, 16] - [3, 17] + ")")) ; [3, 17] - [3, 18] + (comment) ; [4, 8] - [4, 36] + (MISSING ";"))) ; [4, 36] - [4, 36] + "}")) ; [5, 4] - [5, 5] + "}"))) ; [6, 0] - [6, 1] + ]] end) end) |