Mercurial > vim
view src/testdir/test_smartindent.vim @ 34379:37b4c89ba420 v9.1.0116
patch 9.1.0116: win_split_ins may not check available room
Commit: https://github.com/vim/vim/commit/0fd44a5ad81ade342cb54d8984965bdedd2272c8
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date: Tue Feb 20 20:28:15 2024 +0100
patch 9.1.0116: win_split_ins may not check available room
Problem: win_split_ins has no check for E36 when moving an existing
window
Solution: check for room and fix the issues in f_win_splitmove()
(Sean Dewar)
win_split_ins has no check for E36 when moving an existing window,
allowing for layouts with many overlapping zero-sized windows to be
created (which may also cause drawing issues with tablines and such).
f_win_splitmove also has some bugs.
So check for room and fix the issues in f_win_splitmove. Handle failure
in the two relevant win_split_ins callers by restoring the original
layout, and factor the common logic into win_splitmove.
Don't check for room when opening an autocommand window, as it's a
temporary window that's rarely interacted with or drawn anyhow, and is
rather important for some autocommands.
Issues fixed in f_win_splitmove:
- Error if splitting is disallowed.
- Fix heap-use-after-frees if autocommands fired from switching to "targetwin"
close "wp" or "oldwin".
- Fix splitting the wrong window if autocommands fired from switching to
"targetwin" switch to a different window.
- Ensure -1 is returned for all errors.
Also handle allocation failure a bit earlier in make_snapshot (callers,
except win_splitmove, don't really care if a snapshot can't be made, so
just ignore the return value).
Note: Test_smoothscroll_in_zero_width_window failed after these changes with
E36, as it was using the previous behaviour to create a zero-width window.
I've fixed the test such that it fails with UBSAN as expected when v9.0.1367 is
reverted (and simplified it too).
related: #14042
Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 20 Feb 2024 22:30:04 +0100 |
parents | 3942ea75b4c0 |
children |
line wrap: on
line source
" Tests for smartindent " Tests for not doing smart indenting when it isn't set. func Test_nosmartindent() new call append(0, [" some test text", \ " test text", \ "test text", \ " test text"]) set nocindent nosmartindent autoindent exe "normal! gg/some\<CR>" exe "normal! 2cc#test\<Esc>" call assert_equal(" #test", getline(1)) enew! | close endfunc func MyIndent() endfunc " When 'indentexpr' is set, setting 'si' has no effect. func Test_smartindent_has_no_effect() new exe "normal! i\<Tab>one\<Esc>" setlocal noautoindent smartindent indentexpr= exe "normal! Gotwo\<Esc>" call assert_equal("\ttwo", getline("$")) set indentexpr=MyIndent exe "normal! Gothree\<Esc>" call assert_equal("three", getline("$")) delfunction! MyIndent bwipe! endfunc " Test for inserting '{' and '} with smartindent func Test_smartindent_braces() new setlocal smartindent shiftwidth=4 call setline(1, [' if (a)', "\tif (b)", "\t return 1"]) normal 2ggO{ normal 3ggA { normal 4ggo} normal o} normal 4ggO#define FOO 1 call assert_equal([ \ ' if (a)', \ ' {', \ "\tif (b) {", \ '#define FOO 1', \ "\t return 1", \ "\t}", \ ' }' \ ], getline(1, '$')) close! endfunc " Test for adding a new line before and after comments with smartindent func Test_si_add_line_around_comment() new setlocal smartindent shiftwidth=4 call setline(1, [' A', '# comment1', '# comment2']) exe "normal GoC\<Esc>2GOB" call assert_equal([' A', ' B', '# comment1', '# comment2', ' C'], \ getline(1, '$')) close! endfunc " After a C style comment, indent for a following line should line up with the " line containing the start of the comment. func Test_si_indent_after_c_comment() new setlocal smartindent shiftwidth=4 fo+=ro exe "normal i\<C-t>/*\ncomment\n/\n#define FOOBAR\n75\<Esc>ggOabc" normal 3jOcont call assert_equal([' abc', ' /*', ' * comment', ' * cont', \ ' */', '#define FOOBAR', ' 75'], getline(1, '$')) close! endfunc " Test for indenting a statement after a if condition split across lines func Test_si_if_cond_split_across_lines() new setlocal smartindent shiftwidth=4 exe "normal i\<C-t>if (cond1 &&\n\<C-t>cond2) {\ni = 10;\n}" call assert_equal([' if (cond1 &&', "\t cond2) {", "\ti = 10;", \ ' }'], getline(1, '$')) close! endfunc " Test for inserting lines before and after a one line comment func Test_si_one_line_comment() new setlocal smartindent shiftwidth=4 exe "normal i\<C-t>abc;\n\<C-t>/* comment */" normal oi = 10; normal kOj = 1; call assert_equal([' abc;', "\tj = 1;", "\t/* comment */", "\ti = 10;"], \ getline(1, '$')) close! endfunc " Test for smartindent with a comment continued across multiple lines func Test_si_comment_line_continuation() new setlocal smartindent shiftwidth=4 call setline(1, ['# com1', '# com2 \', ' contd', '# com3', ' xyz']) normal ggOabc call assert_equal([' abc', '# com1', '# com2 \', ' contd', '# com3', \ ' xyz'], getline(1, '$')) close! endfunc " When 'paste' is set, 'smartindent' should not take effect. func Test_si_with_paste() new setlocal smartindent autoindent set paste " insert text that will trigger smartindent exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}" exe "norm! Ok = 3;" exe "norm! 4G>>" call assert_equal([' {', 'if (x)', 'i = 1;', '#define FOO 1', \ 'j = 2;', 'k = 3;', '}'], getline(1, '$')) call assert_true(&smartindent) set nopaste %d _ exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}" exe "norm! Ok = 3;" exe "norm! 4G>>" call assert_equal([' {', "\t if (x)", "\t\t i = 1;", \ '#define FOO 1', "\t\t j = 2;", "\t k = 3;", ' }'], \ getline(1, '$')) bw! endfunc func Test_si_after_completion() new setlocal ai smartindent indentexpr= call setline(1, 'foo foot') call feedkeys("o f\<C-X>\<C-N>#", 'tx') call assert_equal(' foo#', getline(2)) call setline(2, '') call feedkeys("1Go f\<C-X>\<C-N>}", 'tx') call assert_equal(' foo}', getline(2)) bwipe! endfunc func Test_no_si_after_completion() new call setline(1, 'foo foot') call feedkeys("o f\<C-X>\<C-N>#", 'tx') call assert_equal(' foo#', getline(2)) bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab