Mercurial > vim
changeset 10242:a369d97995ff v8.0.0019
commit https://github.com/vim/vim/commit/b3435b0a3a0967115658d0a8c0224a28969cfa02
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 29 20:54:59 2016 +0200
patch 8.0.0019
Problem: Test_command_count is old style.
Solution: Turn it into a new style test. (Naruhiko Nishino)
Use more assert functions.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 29 Sep 2016 21:00:05 +0200 |
parents | ba9675005c62 |
children | fe057ff11e5f |
files | src/Makefile src/testdir/Make_all.mak src/testdir/test_alot.vim src/testdir/test_autocmd.vim src/testdir/test_command_count.in src/testdir/test_command_count.ok src/testdir/test_command_count.vim src/version.c |
diffstat | 8 files changed, 206 insertions(+), 198 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile +++ b/src/Makefile @@ -2028,7 +2028,6 @@ test1 \ test_breakindent \ test_changelist \ test_close_count \ - test_command_count \ test_comparators \ test_erasebackword \ test_eval \ @@ -2066,6 +2065,7 @@ test_arglist \ test_channel \ test_charsearch \ test_cmdline \ + test_command_count \ test_crypt \ test_cscope \ test_cursor_func \
--- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -79,7 +79,6 @@ SCRIPTS_ALL = \ test_breakindent.out \ test_changelist.out \ test_close_count.out \ - test_command_count.out \ test_comparators.out \ test_erasebackword.out \ test_eval.out \
--- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -3,6 +3,7 @@ source test_assign.vim source test_autocmd.vim +source test_command_count.vim source test_cursor_func.vim source test_delete.vim source test_execute_func.vim
--- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -1,5 +1,13 @@ " Tests for autocommands +function! s:cleanup_buffers() abort + for bnr in range(1, bufnr('$')) + if bufloaded(bnr) && bufnr('%') != bnr + execute 'bd! ' . bnr + endif + endfor +endfunction + func Test_vim_did_enter() call assert_false(v:vim_did_enter) @@ -254,6 +262,9 @@ endfunc " Tests for autocommands on :close command. " This used to be in test13. func Test_three_windows() + " Clean up buffers, because in some cases this function fails. + call s:cleanup_buffers() + " Write three files and open them, each in a window. " Then go to next window, with autocommand that deletes the previous one. " Do this twice, writing the file.
deleted file mode 100644 --- a/src/testdir/test_command_count.in +++ /dev/null @@ -1,158 +0,0 @@ -Test for user command counts vim: set ft=vim : - -STARTTEST -:so small.vim -:lang C -:let g:lines = [] -:com -range=% RangeLines :call add(g:lines, 'RangeLines '.<line1>.' '.<line2>) -:com -range -addr=arguments RangeArguments :call add(g:lines, 'RangeArguments '.<line1>.' '.<line2>) -:com -range=% -addr=arguments RangeArgumentsAll :call add(g:lines, 'RangeArgumentsAll '.<line1>.' '.<line2>) -:com -range -addr=loaded_buffers RangeLoadedBuffers :call add(g:lines, 'RangeLoadedBuffers '.<line1>.' '.<line2>) -:com -range=% -addr=loaded_buffers RangeLoadedBuffersAll :call add(g:lines, 'RangeLoadedBuffersAll '.<line1>.' '.<line2>) -:com -range -addr=buffers RangeBuffers :call add(g:lines, 'RangeBuffers '.<line1>.' '.<line2>) -:com -range=% -addr=buffers RangeBuffersAll :call add(g:lines, 'RangeBuffersAll '.<line1>.' '.<line2>) -:com -range -addr=windows RangeWindows :call add(g:lines, 'RangeWindows '.<line1>.' '.<line2>) -:com -range=% -addr=windows RangeWindowsAll :call add(g:lines, 'RangeWindowsAll '.<line1>.' '.<line2>) -:com -range -addr=tabs RangeTabs :call add(g:lines, 'RangeTabs '.<line1>.' '.<line2>) -:com -range=% -addr=tabs RangeTabsAll :call add(g:lines, 'RangeTabsAll '.<line1>.' '.<line2>) -:set hidden -:arga a b c d -:argdo echo "loading buffers" -:argu 3 -:.-,$-RangeArguments -:%RangeArguments -:RangeArgumentsAll -:N -:.RangeArguments -:split|split|split|split -:3wincmd w -:.,$RangeWindows -:%RangeWindows -:RangeWindowsAll -:only -:blast|bd -:.,$RangeLoadedBuffers -:%RangeLoadedBuffers -:RangeLoadedBuffersAll -:.,$RangeBuffers -:%RangeBuffers -:RangeBuffersAll -:tabe|tabe|tabe|tabe -:normal 2gt -:.,$RangeTabs -:%RangeTabs -:RangeTabsAll -:1tabonly -:s/\n/\r\r\r\r\r/ -:2ma< -:$-ma> -:'<,'>RangeLines -:com -range=% -buffer LocalRangeLines :call add(g:lines, 'LocalRangeLines '.<line1>.' '.<line2>) -:'<,'>LocalRangeLines -:b1 -ENDTEST - -STARTTEST -:call add(g:lines, '') -:%argd -:arga a b c d -:let v:errmsg = '' -:5argu -:call add(g:lines, '5argu ' . v:errmsg) -:$argu -:call add(g:lines, '4argu ' . expand('%:t')) -:let v:errmsg = '' -:1argu -:call add(g:lines, '1argu ' . expand('%:t')) -:let v:errmsg = '' -:100b -:call add(g:lines, '100b ' . v:errmsg) -:split|split|split|split -:let v:errmsg = '' -:0close -:call add(g:lines, '0close ' . v:errmsg) -:$wincmd w -:$close -:call add(g:lines, '$close ' . winnr()) -:let v:errmsg = '' -:$+close -:call add(g:lines, '$+close ' . v:errmsg) -:$tabe -:call add(g:lines, '$tabe ' . tabpagenr()) -:let v:errmsg = '' -:$+tabe -:call add(g:lines, '$+tabe ' . v:errmsg) -:only! -:e x -:0tabm -:normal 1gt -:call add(g:lines, '0tabm ' . expand('%:t')) -:tabonly! -:only! -:e! test.out -:call append(0, g:lines) -:unlet g:lines -:w|bd -:b1 -ENDTEST - -STARTTEST -:let g:lines = [] -:func BufStatus() -: call add(g:lines, 'aaa: ' . buflisted(g:buf_aaa) . ' bbb: ' . buflisted(g:buf_bbb) . ' ccc: ' . buflisted(g:buf_ccc)) -:endfunc -:se nohidden -:e aaa -:let buf_aaa = bufnr('%') -:e bbb -:let buf_bbb = bufnr('%') -:e ccc -:let buf_ccc = bufnr('%') -:b1 -:call BufStatus() -:exe buf_bbb . "," . buf_ccc . "bdelete" -:call BufStatus() -:exe buf_aaa . "bdelete" -:call BufStatus() -:e! test.out -:call append('$', g:lines) -:unlet g:lines -:delfunc BufStatus -:w|bd -:b1 -ENDTEST - -STARTTEST -:se hidden -:only! -:let g:lines = [] -:%argd -:arga a b c d e f -:3argu -:let args = '' -:.,$-argdo let args .= ' '.expand('%') -:call add(g:lines, 'argdo:' . args) -:split|split|split|split -:2wincmd w -:let windows = '' -:.,$-windo let windows .= ' '.winnr() -:call add(g:lines, 'windo:'. windows) -:b2 -:let buffers = '' -:.,$-bufdo let buffers .= ' '.bufnr('%') -:call add(g:lines, 'bufdo:' . buffers) -:3bd -:let buffers = '' -:3,7bufdo let buffers .= ' '.bufnr('%') -:call add(g:lines, 'bufdo:' . buffers) -:tabe|tabe|tabe|tabe -:normal! 2gt -:let tabpages = '' -:.,$-tabdo let tabpages .= ' '.tabpagenr() -:call add(g:lines, 'tabdo:' . tabpages) -:e! test.out -:call append('$', g:lines) -:w|qa! -ENDTEST - -
deleted file mode 100644 --- a/src/testdir/test_command_count.ok +++ /dev/null @@ -1,38 +0,0 @@ -RangeArguments 2 4 -RangeArguments 1 5 -RangeArgumentsAll 1 5 -RangeArguments 2 2 -RangeWindows 3 5 -RangeWindows 1 5 -RangeWindowsAll 1 5 -RangeLoadedBuffers 2 4 -RangeLoadedBuffers 1 4 -RangeLoadedBuffersAll 1 4 -RangeBuffers 2 5 -RangeBuffers 1 5 -RangeBuffersAll 1 5 -RangeTabs 2 5 -RangeTabs 1 5 -RangeTabsAll 1 5 -RangeLines 2 5 -LocalRangeLines 2 5 - -5argu E16: Invalid range -4argu d -1argu a -100b E16: Invalid range -0close -$close 3 -$+close E16: Invalid range -$tabe 2 -$+tabe E16: Invalid range -0tabm x - -aaa: 1 bbb: 1 ccc: 1 -aaa: 1 bbb: 0 ccc: 0 -aaa: 0 bbb: 0 ccc: 0 -argdo: c d e -windo: 2 3 4 -bufdo: 2 3 4 5 6 7 8 9 10 15 -bufdo: 4 5 6 7 -tabdo: 2 3 4
new file mode 100644 --- /dev/null +++ b/src/testdir/test_command_count.vim @@ -0,0 +1,191 @@ +" Test for user command counts. + +func Test_command_count_0() + set hidden + set noswapfile + + split DoesNotExistEver + let lastbuf = bufnr('$') + call setline(1, 'asdf') + quit! + + command! -range -addr=loaded_buffers RangeLoadedBuffers :let lines = [<line1>, <line2>] + command! -range=% -addr=loaded_buffers RangeLoadedBuffersAll :let lines = [<line1>, <line2>] + command! -range -addr=buffers RangeBuffers :let lines = [<line1>, <line2>] + command! -range=% -addr=buffers RangeBuffersAll :let lines = [<line1>, <line2>] + + .,$RangeLoadedBuffers + call assert_equal([1, 1], lines) + %RangeLoadedBuffers + call assert_equal([1, 1], lines) + RangeLoadedBuffersAll + call assert_equal([1, 1], lines) + .,$RangeBuffers + call assert_equal([1, lastbuf], lines) + %RangeBuffers + call assert_equal([1, lastbuf], lines) + RangeBuffersAll + call assert_equal([1, lastbuf], lines) + + delcommand RangeLoadedBuffers + delcommand RangeLoadedBuffersAll + delcommand RangeBuffers + delcommand RangeBuffersAll + + set hidden& + set swapfile& +endfunc + +func Test_command_count_1() + silent! %argd + arga a b c d e + argdo echo "loading buffers" + argu 3 + command! -range -addr=arguments RangeArguments :let lines = [<line1>, <line2>] + command! -range=% -addr=arguments RangeArgumentsAll :let lines = [<line1>, <line2>] + .-,$-RangeArguments + call assert_equal([2, 4], lines) + %RangeArguments + call assert_equal([1, 5], lines) + RangeArgumentsAll + call assert_equal([1, 5], lines) + N + .RangeArguments + call assert_equal([2, 2], lines) + delcommand RangeArguments + delcommand RangeArgumentsAll + + split|split|split|split + 3wincmd w + command! -range -addr=windows RangeWindows :let lines = [<line1>, <line2>] + .,$RangeWindows + call assert_equal([3, 5], lines) + %RangeWindows + call assert_equal([1, 5], lines) + delcommand RangeWindows + + command! -range=% -addr=windows RangeWindowsAll :let lines = [<line1>, <line2>] + RangeWindowsAll + call assert_equal([1, 5], lines) + delcommand RangeWindowsAll + only + blast|bd + + tabe|tabe|tabe|tabe + normal 2gt + command! -range -addr=tabs RangeTabs :let lines = [<line1>, <line2>] + .,$RangeTabs + call assert_equal([2, 5], lines) + %RangeTabs + call assert_equal([1, 5], lines) + delcommand RangeTabs + + command! -range=% -addr=tabs RangeTabsAll :let lines = [<line1>, <line2>] + RangeTabsAll + call assert_equal([1, 5], lines) + delcommand RangeTabsAll + 1tabonly + + s/\n/\r\r\r\r\r/ + 2ma< + $-ma> + command! -range=% RangeLines :let lines = [<line1>, <line2>] + '<,'>RangeLines + call assert_equal([2, 5], lines) + delcommand RangeLines + + command! -range=% -buffer LocalRangeLines :let lines = [<line1>, <line2>] + '<,'>LocalRangeLines + call assert_equal([2, 5], lines) + delcommand LocalRangeLines +endfunc + +func Test_command_count_2() + silent! %argd + arga a b c d + call assert_fails('5argu', 'E16:') + + $argu + call assert_equal('d', expand('%:t')) + + 1argu + call assert_equal('a', expand('%:t')) + + call assert_fails('300b', 'E16:') + + split|split|split|split + 0close + + $wincmd w + $close + call assert_equal(3, winnr()) + + call assert_fails('$+close', 'E16:') + + $tabe + call assert_equal(2, tabpagenr()) + + call assert_fails('$+tabe', 'E16:') + + only! + e x + 0tabm + normal 1gt + call assert_equal('x', expand('%:t')) + + tabonly! + only! +endfunc + +func Test_command_count_3() + se nohidden + e aaa + let buf_aaa = bufnr('%') + e bbb + let buf_bbb = bufnr('%') + e ccc + let buf_ccc = bufnr('%') + buf 1 + call assert_equal([1, 1, 1], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) + exe buf_bbb . "," . buf_ccc . "bdelete" + call assert_equal([1, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) + exe buf_aaa . "bdelete" + call assert_equal([0, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) +endfunc + +func Test_command_count_4() + %argd + let bufnr = bufnr('$') + 1 + arga aa bb cc dd ee ff + 3argu + let args = [] + .,$-argdo call add(args, expand('%')) + call assert_equal(['cc', 'dd', 'ee'], args) + + " create windows to get 5 + split|split|split|split + 2wincmd w + let windows = [] + .,$-windo call add(windows, winnr()) + call assert_equal([2, 3, 4], windows) + only! + + exe bufnr . 'buf' + let buffers = [] + .,$-bufdo call add(buffers, bufnr('%')) + call assert_equal([bufnr, bufnr + 1, bufnr + 2, bufnr + 3, bufnr + 4], buffers) + + exe (bufnr + 3) . 'bdel' + let buffers = [] + exe (bufnr + 2) . ',' . (bufnr + 5) . "bufdo call add(buffers, bufnr('%'))" + call assert_equal([bufnr + 2, bufnr + 4, bufnr + 5], buffers) + + " create tabpages to get 5 + tabe|tabe|tabe|tabe + normal! 2gt + let tabpages = [] + .,$-tabdo call add(tabpages, tabpagenr()) + call assert_equal([2, 3, 4], tabpages) + tabonly! + bwipe! +endfunc