mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-07 22:10:01 -04:00
tests/indent: test cases with normal o for C/C++
This commit is contained in:
parent
15f0813b6e
commit
8bbe33b10d
3 changed files with 108 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue