robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
1.7 KiB45 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local eq, matches, pcall_err = t.eq, t.matches, t.pcall_err
6local clear, command, api, fn = n.clear, n.command, n.api, n.fn
7
8describe(':retab', function()
9  before_each(clear)
10
11  it('uses the new tab width for C indentation', function()
12    command('setlocal tabstop=8 shiftwidth=0 expandtab')
13    api.nvim_buf_set_lines(0, 0, -1, true, { 'int main() {', 'return 0;', '}' })
14    command('1retab 4')
15    command('normal! gg=G')
16    eq(4, fn.indent(2))
17  end)
18
19  for _, option in ipairs({ 'tabstop', 'vartabstop' }) do
20    it('updates indent folds after changing ' .. option, function()
21      command('setlocal shiftwidth=4 foldmethod=indent ' .. option .. '=8')
22      api.nvim_buf_set_lines(0, 0, -1, true, { 'top', '\tfirst', '\tsecond', 'end' })
23      eq(2, fn.foldlevel(2))
24
25      -- Leave the tabs on lines 2-3 untouched; their width changes with the option.
26      command('1retab 4')
27      eq(1, fn.foldlevel(2))
28    end)
29  end
30
31  it('keeps list enabled when the argument is invalid', function()
32    command('setlocal list')
33    matches('E487:', pcall_err(command, 'retab -1'))
34    eq(true, api.nvim_get_option_value('list', { win = 0 }))
35  end)
36
37  it('keeps the cursor position set by an OptionSet callback in another buffer', function()
38    local other = api.nvim_create_buf(true, false)
39    api.nvim_buf_set_lines(other, 0, -1, true, { 'some text' })
40    command('autocmd OptionSet tabstop buffer ' .. other .. ' | call cursor(1, 6)')
41    command('retab 4')
42    eq(other, api.nvim_get_current_buf())
43    eq({ 1, 5 }, api.nvim_win_get_cursor(0))
44  end)
45end)