From 8bbe33b10d560a1acc7f301421ada332e01b8eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Sun, 18 Apr 2021 00:14:03 +0200 Subject: tests/indent: test cases with `normal o` for C/C++ --- lua/nvim-treesitter/test_utils.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lua/nvim-treesitter/test_utils.lua') diff --git a/lua/nvim-treesitter/test_utils.lua b/lua/nvim-treesitter/test_utils.lua index 5665f3ab..9059aef4 100644 --- a/lua/nvim-treesitter/test_utils.lua +++ b/lua/nvim-treesitter/test_utils.lua @@ -44,4 +44,27 @@ function M.indent_whole_file(file, opts) assert.are.same(before, after) end +-- Open a file, use `normal o` to insert a new line and compare results +-- @param file path to the initial file +-- @param spec a table with keys: +-- on_line: line on which `normal o` is executed +-- text: text inserted in the new line +-- indent: expected indent before the inserted text (string or int) +-- @param opts buffer options passed to M.set_buf_indent_opts +function M.indent_new_line(file, spec, opts) + local before, after = M.run_indent_test(file, function() + -- move to the line and input the new one + vim.cmd(string.format('normal! %dG', spec.on_line)) + vim.cmd(string.format('normal! o%s', spec.text)) + end, opts) + + local indent = type(spec.indent) == 'string' and spec.indent or string.rep(' ', spec.indent) + + -- print('# before:\n', table.concat(before, '\n')) + -- print('# after:\n', table.concat(after, '\n')) + + table.insert(before, spec.on_line + 1, indent .. spec.text) + assert.are.same(before, after) +end + return M -- cgit v1.2.3