vim-patch:8.0.1186: still quite a few old style tests

Problem:    Still quite a few old style tests.
Solution:   Convert old to new style tests. (Yegappan Lakshmanan)
            Avoid ringing the bell while running tests.
4a6fcf8047
This commit is contained in:
Justin M. Keyes 2018-02-02 01:42:17 +01:00
parent c9aafda6ac
commit ce92e784e1
6 changed files with 622 additions and 1 deletions

View File

@ -50,6 +50,7 @@ NEW_TESTS ?= \
test_curswant.res \
test_digraph.res \
test_edit.res \
test_exists.res \
test_diffmode.res \
test_farsi.res \
test_file_size.res \
@ -105,6 +106,7 @@ NEW_TESTS ?= \
test_usercommands.res \
test_vimscript.res \
test_visual.res \
test_winbuf_close.res \
test_window_id.res \
test_writefile.res \
test_alot.res

View File

@ -204,6 +204,9 @@ endif
" Execute the tests in alphabetical order.
for s:test in sort(s:tests)
" Silence, please!
set belloff=all
call RunTheTest(s:test)
if len(v:errors) > 0 && index(s:flaky, s:test) >= 0

View File

@ -480,3 +480,129 @@ func Test_BufleaveWithDelete()
new
bwipe! Xfile1
endfunc
" Test for autocommand that changes the buffer list, when doing ":ball".
func Test_Acmd_BufAll()
enew!
%bwipe!
call writefile(['Test file Xxx1'], 'Xxx1')
call writefile(['Test file Xxx2'], 'Xxx2')
call writefile(['Test file Xxx3'], 'Xxx3')
" Add three files to the buffer list
split Xxx1
close
split Xxx2
close
split Xxx3
close
" Wipe the buffer when the buffer is opened
au BufReadPost Xxx2 bwipe
call append(0, 'Test file Xxx4')
ball
call assert_equal(2, winnr('$'))
call assert_equal('Xxx1', bufname(winbufnr(winnr('$'))))
wincmd t
au! BufReadPost
%bwipe!
call delete('Xxx1')
call delete('Xxx2')
call delete('Xxx3')
enew! | only
endfunc
" Test for autocommand that changes current buffer on BufEnter event.
" Check if modelines are interpreted for the correct buffer.
func Test_Acmd_BufEnter()
%bwipe!
call writefile(['start of test file Xxx1',
\ "\<Tab>this is a test",
\ 'end of test file Xxx1'], 'Xxx1')
call writefile(['start of test file Xxx2',
\ 'vim: set noai :',
\ "\<Tab>this is a test",
\ 'end of test file Xxx2'], 'Xxx2')
au BufEnter Xxx2 brew
set ai modeline modelines=3
edit Xxx1
" edit Xxx2, autocmd will do :brew
edit Xxx2
exe "normal G?this is a\<CR>"
" Append text with autoindent to this file
normal othis should be auto-indented
call assert_equal("\<Tab>this should be auto-indented", getline('.'))
call assert_equal(3, line('.'))
" Remove autocmd and edit Xxx2 again
au! BufEnter Xxx2
buf! Xxx2
exe "normal G?this is a\<CR>"
" append text without autoindent to Xxx
normal othis should be in column 1
call assert_equal("this should be in column 1", getline('.'))
call assert_equal(4, line('.'))
%bwipe!
call delete('Xxx1')
call delete('Xxx2')
set ai&vim modeline&vim modelines&vim
endfunc
" Test for issue #57
" do not move cursor on <c-o> when autoindent is set
func Test_ai_CTRL_O()
enew!
set ai
let save_fo = &fo
set fo+=r
exe "normal o# abcdef\<Esc>2hi\<CR>\<C-O>d0\<Esc>"
exe "normal o# abcdef\<Esc>2hi\<C-O>d0\<Esc>"
call assert_equal(['# abc', 'def', 'def'], getline(2, 4))
set ai&vim
let &fo = save_fo
enew!
endfunc
" Test for autocommand that deletes the current buffer on BufLeave event.
" Also test deleting the last buffer, should give a new, empty buffer.
func Test_BufLeave_Wipe()
%bwipe!
let content = ['start of test file Xxx',
\ 'this is a test',
\ 'end of test file Xxx']
call writefile(content, 'Xxx1')
call writefile(content, 'Xxx2')
au BufLeave Xxx2 bwipe
edit Xxx1
split Xxx2
" delete buffer Xxx2, we should be back to Xxx1
bwipe
call assert_equal('Xxx1', bufname('%'))
call assert_equal(1, winnr('$'))
" Create an alternate buffer
%write! test.out
call assert_equal('test.out', bufname('#'))
" delete alternate buffer
bwipe test.out
call assert_equal('Xxx1', bufname('%'))
call assert_equal('', bufname('#'))
au BufLeave Xxx1 bwipe
" delete current buffer, get an empty one
bwipe!
call assert_equal(1, line('$'))
call assert_equal('', bufname('%'))
call assert_equal(1, len(getbufinfo()))
call delete('Xxx1')
call delete('Xxx2')
%bwipe
au! BufLeave
endfunc

View File

@ -0,0 +1,321 @@
" Tests for the exists() function
func Test_exists()
augroup myagroup
autocmd! BufEnter *.my echo "myfile edited"
autocmd! FuncUndefined UndefFun exec "fu UndefFun()\nendfu"
augroup END
set rtp+=./sautest
" valid autocmd group
call assert_equal(1, exists('#myagroup'))
" valid autocmd group with garbage
call assert_equal(0, exists('#myagroup+b'))
" Valid autocmd group and event
call assert_equal(1, exists('#myagroup#BufEnter'))
" Valid autocmd group, event and pattern
call assert_equal(1, exists('#myagroup#BufEnter#*.my'))
" Valid autocmd event
call assert_equal(1, exists('#BufEnter'))
" Valid autocmd event and pattern
call assert_equal(1, exists('#BufEnter#*.my'))
" Non-existing autocmd group or event
call assert_equal(0, exists('#xyzagroup'))
" Non-existing autocmd group and valid autocmd event
call assert_equal(0, exists('#xyzagroup#BufEnter'))
" Valid autocmd group and event with no matching pattern
call assert_equal(0, exists('#myagroup#CmdwinEnter'))
" Valid autocmd group and non-existing autocmd event
call assert_equal(0, exists('#myagroup#xyzacmd'))
" Valid autocmd group and event and non-matching pattern
call assert_equal(0, exists('#myagroup#BufEnter#xyzpat'))
" Valid autocmd event and non-matching pattern
call assert_equal(0, exists('#BufEnter#xyzpat'))
" Empty autocmd group, event and pattern
call assert_equal(0, exists('###'))
" Empty autocmd group and event or empty event and pattern
call assert_equal(0, exists('##'))
" Valid autocmd event
call assert_equal(1, exists('##FileReadCmd'))
" Non-existing autocmd event
call assert_equal(0, exists('##MySpecialCmd'))
" Existing and working option (long form)
call assert_equal(1, exists('&textwidth'))
" Existing and working option (short form)
call assert_equal(1, exists('&tw'))
" Existing and working option with garbage
call assert_equal(0, exists('&tw-'))
" Global option
call assert_equal(1, exists('&g:errorformat'))
" Local option
call assert_equal(1, exists('&l:errorformat'))
" Negative form of existing and working option (long form)
call assert_equal(0, exists('&nojoinspaces'))
" Negative form of existing and working option (short form)
call assert_equal(0, exists('&nojs'))
" Non-existing option
call assert_equal(0, exists('&myxyzoption'))
" Existing and working option (long form)
call assert_equal(1, exists('+incsearch'))
" Existing and working option with garbage
call assert_equal(0, exists('+incsearch!1'))
" Existing and working option (short form)
call assert_equal(1, exists('+is'))
" Existing option that is hidden.
call assert_equal(0, exists('+autoprint'))
" Existing environment variable
let $EDITOR_NAME = 'Vim Editor'
call assert_equal(1, exists('$EDITOR_NAME'))
" Non-existing environment variable
call assert_equal(0, exists('$NON_ENV_VAR'))
" Valid internal function
call assert_equal(1, exists('*bufnr'))
" Valid internal function with ()
call assert_equal(1, exists('*bufnr()'))
" Non-existing internal function
call assert_equal(0, exists('*myxyzfunc'))
" Valid internal function with garbage
call assert_equal(0, exists('*bufnr&6'))
" Valid user defined function
call assert_equal(1, exists('*Test_exists'))
" Non-existing user defined function
call assert_equal(0, exists('*MyxyzFunc'))
" Function that may be created by FuncUndefined event
call assert_equal(0, exists('*UndefFun'))
" Function that may be created by script autoloading
call assert_equal(0, exists('*footest#F'))
" Valid internal command (full match)
call assert_equal(2, exists(':edit'))
" Valid internal command (full match) with garbage
call assert_equal(0, exists(':edit/a'))
" Valid internal command (partial match)
call assert_equal(1, exists(':q'))
" Non-existing internal command
call assert_equal(0, exists(':invalidcmd'))
" User defined command (full match)
command! MyCmd :echo 'My command'
call assert_equal(2, exists(':MyCmd'))
" User defined command (partial match)
command! MyOtherCmd :echo 'Another command'
call assert_equal(3, exists(':My'))
" Command modifier
call assert_equal(2, exists(':rightbelow'))
" Non-existing user defined command (full match)
delcommand MyCmd
call assert_equal(0, exists(':MyCmd'))
" Non-existing user defined command (partial match)
delcommand MyOtherCmd
call assert_equal(0, exists(':My'))
" Valid local variable
let local_var = 1
call assert_equal(1, exists('local_var'))
" Valid local variable with garbage
call assert_equal(0, exists('local_var%n'))
" Non-existing local variable
unlet local_var
call assert_equal(0, exists('local_var'))
" Non-existing autoload variable that may be autoloaded
call assert_equal(0, exists('footest#x'))
" Valid local list
let local_list = ["blue", "orange"]
call assert_equal(1, exists('local_list'))
" Valid local list item
call assert_equal(1, exists('local_list[1]'))
" Valid local list item with garbage
call assert_equal(0, exists('local_list[1]+5'))
" Invalid local list item
call assert_equal(0, exists('local_list[2]'))
" Non-existing local list
unlet local_list
call assert_equal(0, exists('local_list'))
" Valid local dictionary
let local_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('local_dict'))
" Non-existing local dictionary
unlet local_dict
call assert_equal(0, exists('local_dict'))
" Existing local curly-brace variable
let str = "local"
let curly_{str}_var = 1
call assert_equal(1, exists('curly_{str}_var'))
" Non-existing local curly-brace variable
unlet curly_{str}_var
call assert_equal(0, exists('curly_{str}_var'))
" Existing global variable
let g:global_var = 1
call assert_equal(1, exists('g:global_var'))
" Existing global variable with garbage
call assert_equal(0, exists('g:global_var-n'))
" Non-existing global variable
unlet g:global_var
call assert_equal(0, exists('g:global_var'))
" Existing global list
let g:global_list = ["blue", "orange"]
call assert_equal(1, exists('g:global_list'))
" Non-existing global list
unlet g:global_list
call assert_equal(0, exists('g:global_list'))
" Existing global dictionary
let g:global_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('g:global_dict'))
" Non-existing global dictionary
unlet g:global_dict
call assert_equal(0, exists('g:global_dict'))
" Existing global curly-brace variable
let str = "global"
let g:curly_{str}_var = 1
call assert_equal(1, exists('g:curly_{str}_var'))
" Non-existing global curly-brace variable
unlet g:curly_{str}_var
call assert_equal(0, exists('g:curly_{str}_var'))
" Existing window variable
let w:window_var = 1
call assert_equal(1, exists('w:window_var'))
" Non-existing window variable
unlet w:window_var
call assert_equal(0, exists('w:window_var'))
" Existing window list
let w:window_list = ["blue", "orange"]
call assert_equal(1, exists('w:window_list'))
" Non-existing window list
unlet w:window_list
call assert_equal(0, exists('w:window_list'))
" Existing window dictionary
let w:window_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('w:window_dict'))
" Non-existing window dictionary
unlet w:window_dict
call assert_equal(0, exists('w:window_dict'))
" Existing window curly-brace variable
let str = "window"
let w:curly_{str}_var = 1
call assert_equal(1, exists('w:curly_{str}_var'))
" Non-existing window curly-brace variable
unlet w:curly_{str}_var
call assert_equal(0, exists('w:curly_{str}_var'))
" Existing tab variable
let t:tab_var = 1
call assert_equal(1, exists('t:tab_var'))
" Non-existing tab variable
unlet t:tab_var
call assert_equal(0, exists('t:tab_var'))
" Existing tab list
let t:tab_list = ["blue", "orange"]
call assert_equal(1, exists('t:tab_list'))
" Non-existing tab list
unlet t:tab_list
call assert_equal(0, exists('t:tab_list'))
" Existing tab dictionary
let t:tab_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('t:tab_dict'))
" Non-existing tab dictionary
unlet t:tab_dict
call assert_equal(0, exists('t:tab_dict'))
" Existing tab curly-brace variable
let str = "tab"
let t:curly_{str}_var = 1
call assert_equal(1, exists('t:curly_{str}_var'))
" Non-existing tab curly-brace variable
unlet t:curly_{str}_var
call assert_equal(0, exists('t:curly_{str}_var'))
" Existing buffer variable
let b:buffer_var = 1
call assert_equal(1, exists('b:buffer_var'))
" Non-existing buffer variable
unlet b:buffer_var
call assert_equal(0, exists('b:buffer_var'))
" Existing buffer list
let b:buffer_list = ["blue", "orange"]
call assert_equal(1, exists('b:buffer_list'))
" Non-existing buffer list
unlet b:buffer_list
call assert_equal(0, exists('b:buffer_list'))
" Existing buffer dictionary
let b:buffer_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('b:buffer_dict'))
" Non-existing buffer dictionary
unlet b:buffer_dict
call assert_equal(0, exists('b:buffer_dict'))
" Existing buffer curly-brace variable
let str = "buffer"
let b:curly_{str}_var = 1
call assert_equal(1, exists('b:curly_{str}_var'))
" Non-existing buffer curly-brace variable
unlet b:curly_{str}_var
call assert_equal(0, exists('b:curly_{str}_var'))
" Existing Vim internal variable
call assert_equal(1, exists('v:version'))
" Non-existing Vim internal variable
call assert_equal(0, exists('v:non_exists_var'))
" Existing script-local variable
let s:script_var = 1
call assert_equal(1, exists('s:script_var'))
" Non-existing script-local variable
unlet s:script_var
call assert_equal(0, exists('s:script_var'))
" Existing script-local list
let s:script_list = ["blue", "orange"]
call assert_equal(1, exists('s:script_list'))
" Non-existing script-local list
unlet s:script_list
call assert_equal(0, exists('s:script_list'))
" Existing script-local dictionary
let s:script_dict = {"xcord":100, "ycord":2}
call assert_equal(1, exists('s:script_dict'))
" Non-existing script-local dictionary
unlet s:script_dict
call assert_equal(0, exists('s:script_dict'))
" Existing script curly-brace variable
let str = "script"
let s:curly_{str}_var = 1
call assert_equal(1, exists('s:curly_{str}_var'))
" Non-existing script-local curly-brace variable
unlet s:curly_{str}_var
call assert_equal(0, exists('s:curly_{str}_var'))
" Existing script-local function
function! s:my_script_func()
endfunction
echo '*s:my_script_func: 1'
call assert_equal(1, exists('*s:my_script_func'))
" Non-existing script-local function
delfunction s:my_script_func
call assert_equal(0, exists('*s:my_script_func'))
unlet str
call assert_equal(1, g:footest#x)
call assert_equal(0, footest#F())
call assert_equal(0, UndefFun())
endfunc
" exists() test for Function arguments
func FuncArg_Tests(func_arg, ...)
call assert_equal(1, exists('a:func_arg'))
call assert_equal(0, exists('a:non_exists_arg'))
call assert_equal(1, exists('a:1'))
call assert_equal(0, exists('a:2'))
endfunc
func Test_exists_funcarg()
call FuncArg_Tests("arg1", "arg2")
endfunc

View File

@ -15,4 +15,49 @@ func Test_recover_root_dir()
set dir&
endfunc
" TODO: move recover tests from test78.in to here.
" Inserts 10000 lines with text to fill the swap file with two levels of pointer
" blocks. Then recovers from the swap file and checks all text is restored.
"
" We need about 10000 lines of 100 characters to get two levels of pointer
" blocks.
func Test_swap_file()
set directory=.
set fileformat=unix undolevels=-1 belloff=all
edit! Xtest
let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
let i = 1
let linecount = 10000
while i <= linecount
call append(i - 1, i . text)
let i += 1
endwhile
$delete
preserve
" get the name of the swap file
let swname = split(execute("swapname"))[0]
let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '')
" make a copy of the swap file in Xswap
set binary
exe 'sp ' . swname
w! Xswap
set nobinary
new
only!
bwipe! Xtest
call rename('Xswap', swname)
recover Xtest
call delete(swname)
let linedollar = line('$')
call assert_equal(linecount, linedollar)
if linedollar < linecount
let linecount = linedollar
endif
let i = 1
while i <= linecount
call assert_equal(i . text, getline(i))
let i += 1
endwhile
set undolevels&
enew! | only
endfunc

View File

@ -0,0 +1,124 @@
" Test for commands that close windows and/or buffers:
" :quit
" :close
" :hide
" :only
" :sall
" :all
" :ball
" :buf
" :edit
"
func Test_winbuf_close()
enew | only
call writefile(['testtext 1'], 'Xtest1')
call writefile(['testtext 2'], 'Xtest2')
call writefile(['testtext 3'], 'Xtest3')
next! Xtest1 Xtest2
call setline(1, 'testtext 1 1')
" test for working :n when hidden set
set hidden
next
call assert_equal('Xtest2', bufname('%'))
" test for failing :rew when hidden not set
set nohidden
call setline(1, 'testtext 2 2')
call assert_fails('rewind', 'E37')
call assert_equal('Xtest2', bufname('%'))
call assert_equal('testtext 2 2', getline(1))
" test for working :rew when hidden set
set hidden
rewind
call assert_equal('Xtest1', bufname('%'))
call assert_equal('testtext 1 1', getline(1))
" test for :all keeping a buffer when it's modified
set nohidden
call setline(1, 'testtext 1 1 1')
split
next Xtest2 Xtest3
all
1wincmd w
call assert_equal('Xtest1', bufname('%'))
call assert_equal('testtext 1 1 1', getline(1))
" test abandoning changed buffer, should be unloaded even when 'hidden' set
set hidden
call setline(1, 'testtext 1 1 1 1')
quit!
call assert_equal('Xtest2', bufname('%'))
call assert_equal('testtext 2 2', getline(1))
unhide
call assert_equal('Xtest2', bufname('%'))
call assert_equal('testtext 2 2', getline(1))
" test ":hide" hides anyway when 'hidden' not set
set nohidden
call setline(1, 'testtext 2 2 2')
hide
call assert_equal('Xtest3', bufname('%'))
call assert_equal('testtext 3', getline(1))
" test ":edit" failing in modified buffer when 'hidden' not set
call setline(1, 'testtext 3 3')
call assert_fails('edit Xtest1', 'E37')
call assert_equal('Xtest3', bufname('%'))
call assert_equal('testtext 3 3', getline(1))
" test ":edit" working in modified buffer when 'hidden' set
set hidden
edit Xtest1
call assert_equal('Xtest1', bufname('%'))
call assert_equal('testtext 1', getline(1))
" test ":close" not hiding when 'hidden' not set in modified buffer
split Xtest3
set nohidden
call setline(1, 'testtext 3 3 3')
call assert_fails('close', 'E37')
call assert_equal('Xtest3', bufname('%'))
call assert_equal('testtext 3 3 3', getline(1))
" test ":close!" does hide when 'hidden' not set in modified buffer;
call setline(1, 'testtext 3 3 3 3')
close!
call assert_equal('Xtest1', bufname('%'))
call assert_equal('testtext 1', getline(1))
set nohidden
" test ":all!" hides changed buffer
split Xtest4
call setline(1, 'testtext 4')
all!
1wincmd w
call assert_equal('Xtest2', bufname('%'))
call assert_equal('testtext 2 2 2', getline(1))
" test ":q!" and hidden buffer.
bwipe! Xtest1 Xtest2 Xtest3 Xtest4
split Xtest1
wincmd w
bwipe!
set modified
bot split Xtest2
set modified
bot split Xtest3
set modified
wincmd t
hide
call assert_equal('Xtest2', bufname('%'))
quit!
call assert_equal('Xtest3', bufname('%'))
call assert_fails('silent! quit!', 'E162')
call assert_equal('Xtest1', bufname('%'))
call delete('Xtest1')
call delete('Xtest2')
call delete('Xtest3')
endfunc