diff options
| author | Jędrzej Boczar <yendreij@gmail.com> | 2021-04-18 00:14:03 +0200 |
|---|---|---|
| committer | Kiyan <yazdani.kiyan@protonmail.com> | 2021-04-23 21:21:38 +0200 |
| commit | 8bbe33b10d560a1acc7f301421ada332e01b8eb2 (patch) | |
| tree | 8926a00bc537403b24a465a5e3060f131426607b /lua/nvim-treesitter/test_utils.lua | |
| parent | 15f0813b6e0682e3f2c3b611610f6ef67cc87449 (diff) | |
tests/indent: test cases with `normal o` for C/C++
Diffstat (limited to 'lua/nvim-treesitter/test_utils.lua')
| -rw-r--r-- | lua/nvim-treesitter/test_utils.lua | 23 |
1 files changed, 23 insertions, 0 deletions
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 |
