# HG changeset patch # User Bram Moolenaar # Date 1583523904 -3600 # Node ID 6d3c683466f4f1430792cf586bd6668259a82a83 # Parent 03c12433ae3631e87bb0dd704f94d5ed9cdcdd84 patch 8.2.0358: insufficient testing for indent.c Commit: https://github.com/vim/vim/commit/bd7206e02c957f0619e68e1628e2a3e91dd41e06 Author: Bram Moolenaar Date: Fri Mar 6 20:36:04 2020 +0100 patch 8.2.0358: insufficient testing for indent.c Problem: Insufficient testing for indent.c. Solution: Add indent tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5736) diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -146,6 +146,7 @@ NEW_TESTS = \ test_iminsert \ test_increment \ test_increment_dbcs \ + test_indent \ test_ins_complete \ test_interrupt \ test_job_fails \ @@ -376,6 +377,7 @@ NEW_TESTS_RES = \ test_iminsert.res \ test_increment.res \ test_increment_dbcs.res \ + test_indent.res \ test_ins_complete.res \ test_interrupt.res \ test_job_fails.res \ diff --git a/src/testdir/test_ex_mode.vim b/src/testdir/test_ex_mode.vim --- a/src/testdir/test_ex_mode.vim +++ b/src/testdir/test_ex_mode.vim @@ -54,6 +54,7 @@ func Test_ex_mode() " default wildchar interferes with this test set wildchar= call assert_equal(["a\tb", "a\tb"], Ex("a\t\t\b"), e) + call assert_equal(["\t mn", "\tm\n"], Ex("\tm\n"), e) set wildchar& endfor diff --git a/src/testdir/test_expand_func.vim b/src/testdir/test_expand_func.vim --- a/src/testdir/test_expand_func.vim +++ b/src/testdir/test_expand_func.vim @@ -73,3 +73,17 @@ func Test_expand() " Don't add any line above this, otherwise will change. quit endfunc + +" Test for 'wildignore' with expand() +func Test_expand_wildignore() + set wildignore=*.vim + call assert_equal('', expand('test_expand_func.vim')) + call assert_equal('', expand('test_expand_func.vim', 0)) + call assert_equal([], expand('test_expand_func.vim', 0, 1)) + call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1)) + call assert_equal(['test_expand_func.vim'], + \ expand('test_expand_func.vim', 1, 1)) + set wildignore& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_indent.vim b/src/testdir/test_indent.vim new file mode 100644 --- /dev/null +++ b/src/testdir/test_indent.vim @@ -0,0 +1,101 @@ +" Test for various indent options + +func Test_preserveindent() + new + " Test for autoindent copying indent from the previous line + setlocal autoindent + call setline(1, [repeat(' ', 16) .. 'line1']) + call feedkeys("A\nline2", 'xt') + call assert_equal("\t\tline2", getline(2)) + setlocal autoindent& + + " Test for using CTRL-T with and without 'preserveindent' + set shiftwidth=4 + call cursor(1, 1) + call setline(1, " \t ") + call feedkeys("Al\", 'xt') + call assert_equal("\t\tl", getline(1)) + set preserveindent + call setline(1, " \t ") + call feedkeys("Al\", 'xt') + call assert_equal(" \t \tl", getline(1)) + set pi& sw& + + " Test for using CTRL-T with 'expandtab' and 'preserveindent' + call cursor(1, 1) + call setline(1, "\t \t") + set shiftwidth=4 expandtab preserveindent + call feedkeys("Al\", 'xt') + call assert_equal("\t \t l", getline(1)) + set sw& et& pi& + + close! +endfunc + +" Test for indent() +func Test_indent_func() + call assert_equal(-1, indent(-1)) + new + call setline(1, "\tabc") + call assert_equal(8, indent(1)) + call setline(1, " abc") + call assert_equal(4, indent(1)) + call setline(1, " \t abc") + call assert_equal(12, indent(1)) + close! +endfunc + +" Test for reindenting a line using the '=' operator +func Test_reindent() + new + call setline(1, 'abc') + set nomodifiable + call assert_fails('normal ==', 'E21:') + set modifiable + + call setline(1, ['foo', 'bar']) + call feedkeys('ggVG=', 'xt') + call assert_equal(['foo', 'bar'], getline(1, 2)) + close! +endfunc + +" Test for shifting a line with a preprocessor directive ('#') +func Test_preproc_indent() + new + set sw=4 + call setline(1, '#define FOO 1') + normal >> + call assert_equal(' #define FOO 1', getline(1)) + + " with 'smartindent' + call setline(1, '#define FOO 1') + set smartindent + normal >> + call assert_equal('#define FOO 1', getline(1)) + set smartindent& + + " with 'cindent' + set cindent + normal >> + call assert_equal('#define FOO 1', getline(1)) + set cindent& + + close! +endfunc + +" Test for 'copyindent' +func Test_copyindent() + new + set shiftwidth=4 autoindent expandtab copyindent + call setline(1, " \t abc") + call feedkeys("ol", 'xt') + call assert_equal(" \t l", getline(2)) + set noexpandtab + call setline(1, " \t abc") + call feedkeys("ol", 'xt') + call assert_equal(" \t l", getline(2)) + set sw& ai& et& ci& + close! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_lispwords.vim b/src/testdir/test_lispwords.vim --- a/src/testdir/test_lispwords.vim +++ b/src/testdir/test_lispwords.vim @@ -45,6 +45,7 @@ func Test_lisp_indent() \ ]) call assert_equal(7, lispindent(2)) call assert_equal(5, 6->lispindent()) + call assert_equal(-1, lispindent(-1)) set lisp set lispwords& @@ -83,3 +84,5 @@ func Test_lisp_indent() let &cpoptions=save_copt set nolisp endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_smartindent.vim b/src/testdir/test_smartindent.vim --- a/src/testdir/test_smartindent.vim +++ b/src/testdir/test_smartindent.vim @@ -38,4 +38,27 @@ func Test_smartindent_has_no_effect() bwipe! endfunc +" Test for inserting '{' and '} with smartindent +func Test_smartindent_braces() + new + set 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, '$')) + set si& sw& ai& + close! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_vartabs.vim b/src/testdir/test_vartabs.vim --- a/src/testdir/test_vartabs.vim +++ b/src/testdir/test_vartabs.vim @@ -91,6 +91,18 @@ func Test_vartabs() let expect = "l\ l\l l\ l\ l" call assert_equal(expect, getline(1)) + " Test for 'retab' with vts + set ts=8 sts=0 vts=5,3,6,2 vsts= + exe "norm! S l" + .retab! + call assert_equal("\t\t\t\tl", getline(1)) + + " Test for 'retab' with same vlaues as vts + set ts=8 sts=0 vts=5,3,6,2 vsts= + exe "norm! S l" + .retab! 5,3,6,2 + call assert_equal("\t\t\t\tl", getline(1)) + " Check that global and local values are set. set ts=4 vts=6 sts=8 vsts=10 call assert_equal(&ts, 4) @@ -378,3 +390,33 @@ func Test_vartabs_reset() set all& call assert_equal('', &vts) endfunc + +func s:SaveCol(l) + call add(a:l, [col('.'), virtcol('.')]) + return '' +endfunc + +" Test for 'varsofttabstop' +func Test_varsofttabstop() + new + inoremap s:SaveCol(g:cols) + + set backspace=indent,eol,start + set varsofttabstop=6,2,5,3 + let g:cols = [] + call feedkeys("a\t\\t\\t\\t\ ", 'xt') + call assert_equal("\t\t ", getline(1)) + call assert_equal([[7, 7], [2, 9], [7, 14], [3, 17]], g:cols) + + let g:cols = [] + call feedkeys("a\\\\\\\\\\", 'xt') + call assert_equal('', getline(1)) + call assert_equal([[3, 17], [7, 14], [2, 9], [7, 7], [1, 1]], g:cols) + + set varsofttabstop& + set backspace& + iunmap + close! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 358, +/**/ 357, /**/ 356,