Merge pull request #17583 from zeertzjq/test-old-missing

test(old): add more missing test files and run more tests alone
This commit is contained in:
zeertzjq 2022-03-03 13:52:49 +08:00 committed by GitHub
commit f9db491a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 212 additions and 182 deletions

View File

@ -3,56 +3,33 @@
source test_backup.vim source test_backup.vim
source test_behave.vim source test_behave.vim
source test_cd.vim
source test_changedtick.vim
source test_compiler.vim source test_compiler.vim
source test_cursor_func.vim
source test_cursorline.vim
source test_ex_equal.vim source test_ex_equal.vim
source test_ex_undo.vim source test_ex_undo.vim
source test_ex_z.vim source test_ex_z.vim
source test_ex_mode.vim source test_ex_mode.vim
source test_execute_func.vim source test_expand.vim
source test_expand_func.vim source test_expand_func.vim
source test_feedkeys.vim source test_feedkeys.vim
source test_filter_cmd.vim source test_file_perm.vim
source test_filter_map.vim source test_fnamemodify.vim
source test_findfile.vim
source test_float_func.vim
source test_functions.vim
source test_ga.vim source test_ga.vim
source test_glob2regpat.vim
source test_global.vim source test_global.vim
source test_goto.vim
source test_join.vim
source test_jumps.vim source test_jumps.vim
source test_fileformat.vim source test_lispwords.vim
source test_filetype.vim
source test_filetype_lua.vim
source test_lambda.vim
source test_menu.vim source test_menu.vim
source test_messages.vim
source test_modeline.vim
source test_move.vim source test_move.vim
source test_partial.vim
source test_popup.vim
source test_put.vim source test_put.vim
source test_rename.vim source test_reltime.vim
source test_scroll_opt.vim source test_scroll_opt.vim
source test_searchpos.vim
source test_set.vim
source test_shift.vim source test_shift.vim
" Test fails on windows CI when using the MSVC compiler.
" source test_sort.vim
source test_sha256.vim source test_sha256.vim
source test_suspend.vim
source test_syn_attr.vim
source test_tabline.vim source test_tabline.vim
source test_tabpage.vim
source test_tagcase.vim source test_tagcase.vim
source test_tagfunc.vim source test_tagfunc.vim
source test_tagjump.vim
source test_taglist.vim
source test_true_false.vim
source test_unlet.vim source test_unlet.vim
source test_version.vim source test_version.vim
source test_virtualedit.vim
source test_window_cmd.vim
source test_wnext.vim source test_wnext.vim

View File

@ -0,0 +1,114 @@
" Test for delete().
func Test_file_delete()
split Xfile
call setline(1, ['a', 'b'])
wq
call assert_equal(['a', 'b'], readfile('Xfile'))
call assert_equal(0, delete('Xfile'))
call assert_fails('call readfile("Xfile")', 'E484:')
call assert_equal(-1, delete('Xfile'))
bwipe Xfile
endfunc
func Test_dir_delete()
call mkdir('Xdir1')
call assert_true(isdirectory('Xdir1'))
call assert_equal(0, delete('Xdir1', 'd'))
call assert_false(isdirectory('Xdir1'))
call assert_equal(-1, delete('Xdir1', 'd'))
endfunc
func Test_recursive_delete()
call mkdir('Xdir1')
call mkdir('Xdir1/subdir')
call mkdir('Xdir1/empty')
split Xdir1/Xfile
call setline(1, ['a', 'b'])
w
w Xdir1/subdir/Xfile
close
call assert_true(isdirectory('Xdir1'))
call assert_equal(['a', 'b'], readfile('Xdir1/Xfile'))
call assert_true(isdirectory('Xdir1/subdir'))
call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile'))
call assert_true('Xdir1/empty'->isdirectory())
call assert_equal(0, delete('Xdir1', 'rf'))
call assert_false(isdirectory('Xdir1'))
call assert_equal(-1, delete('Xdir1', 'd'))
bwipe Xdir1/Xfile
bwipe Xdir1/subdir/Xfile
endfunc
func Test_symlink_delete()
if !has('unix')
return
endif
split Xfile
call setline(1, ['a', 'b'])
wq
silent !ln -s Xfile Xlink
" Delete the link, not the file
call assert_equal(0, delete('Xlink'))
call assert_equal(-1, delete('Xlink'))
call assert_equal(0, delete('Xfile'))
bwipe Xfile
endfunc
func Test_symlink_dir_delete()
if !has('unix')
return
endif
call mkdir('Xdir1')
silent !ln -s Xdir1 Xlink
call assert_true(isdirectory('Xdir1'))
call assert_true(isdirectory('Xlink'))
" Delete the link, not the directory
call assert_equal(0, delete('Xlink'))
call assert_equal(-1, delete('Xlink'))
call assert_equal(0, delete('Xdir1', 'd'))
endfunc
func Test_symlink_recursive_delete()
if !has('unix')
return
endif
call mkdir('Xdir3')
call mkdir('Xdir3/subdir')
call mkdir('Xdir4')
split Xdir3/Xfile
call setline(1, ['a', 'b'])
w
w Xdir3/subdir/Xfile
w Xdir4/Xfile
close
silent !ln -s ../Xdir4 Xdir3/Xlink
call assert_true(isdirectory('Xdir3'))
call assert_equal(['a', 'b'], readfile('Xdir3/Xfile'))
call assert_true(isdirectory('Xdir3/subdir'))
call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile'))
call assert_true(isdirectory('Xdir4'))
call assert_true(isdirectory('Xdir3/Xlink'))
call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
call assert_equal(0, delete('Xdir3', 'rf'))
call assert_false(isdirectory('Xdir3'))
call assert_equal(-1, delete('Xdir3', 'd'))
" symlink is deleted, not the directory it points to
call assert_true(isdirectory('Xdir4'))
call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
call assert_equal(0, delete('Xdir4/Xfile'))
call assert_equal(0, delete('Xdir4', 'd'))
bwipe Xdir3/Xfile
bwipe Xdir3/subdir/Xfile
bwipe Xdir4/Xfile
endfunc
func Test_delete_errors()
call assert_fails('call delete('''')', 'E474:')
call assert_fails('call delete(''foo'', 0)', 'E15:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -0,0 +1,30 @@
" Test getting and setting file permissions.
func Test_file_perm()
call assert_equal('', getfperm('Xtest'))
call assert_equal(0, 'Xtest'->setfperm('r--------'))
call writefile(['one'], 'Xtest')
call assert_true(len('Xtest'->getfperm()) == 9)
call assert_equal(1, setfperm('Xtest', 'rwx------'))
if has('win32')
call assert_equal('rw-rw-rw-', getfperm('Xtest'))
else
call assert_equal('rwx------', getfperm('Xtest'))
endif
call assert_equal(1, setfperm('Xtest', 'r--r--r--'))
call assert_equal('r--r--r--', getfperm('Xtest'))
call assert_fails("setfperm('Xtest', '---')")
call assert_equal(1, setfperm('Xtest', 'rwx------'))
call delete('Xtest')
call assert_fails("call setfperm(['Xfile'], 'rw-rw-rw-')", 'E730:')
call assert_fails("call setfperm('Xfile', [])", 'E730:')
call assert_fails("call setfperm('Xfile', 'rwxrwxrwxrw')", 'E475:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -0,0 +1,30 @@
" Tests for searchpos()
func Test_searchpos()
new one
0put ='1a3'
1put ='123xyz'
call cursor(1, 1)
call assert_equal([1, 1, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
call cursor(1, 2)
call assert_equal([2, 1, 1], '\%(\([a-z]\)\|\_.\)\{-}xyz'->searchpos('pcW'))
set cpo-=c
call cursor(1, 2)
call assert_equal([1, 2, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
call cursor(1, 3)
call assert_equal([1, 3, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
" Now with \zs, first match is in column 0, "a" is matched.
call cursor(1, 3)
call assert_equal([2, 4, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcW'))
" With z flag start at cursor column, don't see the "a".
call cursor(1, 3)
call assert_equal([2, 4, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcWz'))
set cpo+=c
" close the window
q!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -0,0 +1,29 @@
" Tests for the :set command
function Test_set_backslash()
let isk_save = &isk
set isk=a,b,c
set isk+=d
call assert_equal('a,b,c,d', &isk)
set isk+=\\,e
call assert_equal('a,b,c,d,\,e', &isk)
set isk-=e
call assert_equal('a,b,c,d,\', &isk)
set isk-=\\
call assert_equal('a,b,c,d', &isk)
let &isk = isk_save
endfunction
function Test_set_add()
let wig_save = &wig
set wildignore=*.png,
set wildignore+=*.jpg
call assert_equal('*.png,*.jpg', &wig)
let &wig = wig_save
endfunction
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -12,6 +12,7 @@ func Compare2(a, b) abort
endfunc endfunc
func Test_sort_strings() func Test_sort_strings()
CheckNotMSWindows " FIXME: Why does this fail with MSVC?
" numbers compared as strings " numbers compared as strings
call assert_equal([1, 2, 3], sort([3, 2, 1])) call assert_equal([1, 2, 3], sort([3, 2, 1]))
call assert_equal([13, 28, 3], sort([3, 28, 13])) call assert_equal([13, 28, 3], sort([3, 28, 13]))

View File

@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source local clear, source = helpers.clear, helpers.source
local eq, eval, command = helpers.eq, helpers.eval, helpers.command local eq, eval, command = helpers.eq, helpers.eval, helpers.command
local exc_exec = helpers.exc_exec
describe('Test for delete()', function() describe('Test for delete()', function()
before_each(clear) before_each(clear)
@ -9,42 +8,6 @@ describe('Test for delete()', function()
os.remove('Xfile') os.remove('Xfile')
end) end)
it('file delete', function()
command('split Xfile')
command("call setline(1, ['a', 'b'])")
command('wq')
eq(eval("['a', 'b']"), eval("readfile('Xfile')"))
eq(0, eval("delete('Xfile')"))
eq(-1, eval("delete('Xfile')"))
end)
it('directory delete', function()
command("call mkdir('Xdir1')")
eq(1, eval("isdirectory('Xdir1')"))
eq(0, eval("delete('Xdir1', 'd')"))
eq(0, eval("isdirectory('Xdir1')"))
eq(-1, eval("delete('Xdir1', 'd')"))
end)
it('recursive delete', function()
command("call mkdir('Xdir1')")
command("call mkdir('Xdir1/subdir')")
command("call mkdir('Xdir1/empty')")
command('split Xdir1/Xfile')
command("call setline(1, ['a', 'b'])")
command('w')
command('w Xdir1/subdir/Xfile')
command('close')
eq(1, eval("isdirectory('Xdir1')"))
eq(eval("['a', 'b']"), eval("readfile('Xdir1/Xfile')"))
eq(1, eval("isdirectory('Xdir1/subdir')"))
eq(eval("['a', 'b']"), eval("readfile('Xdir1/subdir/Xfile')"))
eq(1, eval("'Xdir1/empty'->isdirectory()"))
eq(0, eval("delete('Xdir1', 'rf')"))
eq(0, eval("isdirectory('Xdir1')"))
eq(-1, eval("delete('Xdir1', 'd')"))
end)
it('symlink delete', function() it('symlink delete', function()
source([[ source([[
split Xfile split Xfile
@ -115,10 +78,4 @@ describe('Test for delete()', function()
eq(0, eval("delete('Xdir4/Xfile')")) eq(0, eval("delete('Xdir4/Xfile')"))
eq(0, eval("delete('Xdir4', 'd')")) eq(0, eval("delete('Xdir4', 'd')"))
end) end)
it('gives correct emsgs', function()
eq('Vim(call):E474: Invalid argument', exc_exec("call delete('')"))
eq('Vim(call):E15: Invalid expression: 0',
exc_exec("call delete('foo', 0)"))
end)
end) end)

View File

@ -1,43 +0,0 @@
-- Test getting and setting file permissions.
require('os')
local helpers = require('test.functional.helpers')(after_each)
local clear, call, eq = helpers.clear, helpers.call, helpers.eq
local neq, exc_exec, eval = helpers.neq, helpers.exc_exec, helpers.eval
describe('Test getting and setting file permissions', function()
local tempfile = helpers.tmpname()
before_each(function()
os.remove(tempfile)
clear()
end)
it('file permissions', function()
-- eval() is used to test VimL method syntax for setfperm() and getfperm()
eq('', call('getfperm', tempfile))
eq(0, eval("'" .. tempfile .. "'->setfperm('r--------')"))
call('writefile', {'one'}, tempfile)
eq(9, eval("len('" .. tempfile .. "'->getfperm())"))
eq(1, call('setfperm', tempfile, 'rwx------'))
if helpers.is_os('win') then
eq('rw-rw-rw-', call('getfperm', tempfile))
else
eq('rwx------', call('getfperm', tempfile))
end
eq(1, call('setfperm', tempfile, 'r--r--r--'))
eq('r--r--r--', call('getfperm', tempfile))
local err = exc_exec(('call setfperm("%s", "---")'):format(tempfile))
neq(err:find('E475:'), nil)
eq(1, call('setfperm', tempfile, 'rwx------'))
end)
after_each(function()
os.remove(tempfile)
end)
end)

View File

@ -1,35 +0,0 @@
local helpers = require('test.functional.helpers')(after_each)
local call = helpers.call
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local insert = helpers.insert
describe('searchpos', function()
before_each(clear)
it('is working', function()
insert([[
1a3
123xyz]])
call('cursor', 1, 1)
eq({1, 1, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
call('cursor', 1, 2)
eq({2, 1, 1}, eval([['\%(\([a-z]\)\|\_.\)\{-}xyz'->searchpos('pcW')]]))
command('set cpo-=c')
call('cursor', 1, 2)
eq({1, 2, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
call('cursor', 1, 3)
eq({1, 3, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
-- Now with \zs, first match is in column 0, "a" is matched.
call('cursor', 1, 3)
eq({2, 4, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcW')]]))
-- With z flag start at cursor column, don't see the "a".
call('cursor', 1, 3)
eq({2, 4, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcWz')]]))
end)
end)

View File

@ -1,30 +0,0 @@
-- Tests for :set
local helpers = require('test.functional.helpers')(after_each)
local clear, command, eval, eq =
helpers.clear, helpers.command, helpers.eval, helpers.eq
describe(':set', function()
before_each(clear)
it('handles backslash properly', function()
command('set iskeyword=a,b,c')
command('set iskeyword+=d')
eq('a,b,c,d', eval('&iskeyword'))
command([[set iskeyword+=\\,e]])
eq([[a,b,c,d,\,e]], eval('&iskeyword'))
command('set iskeyword-=e')
eq([[a,b,c,d,\]], eval('&iskeyword'))
command([[set iskeyword-=\]])
eq('a,b,c,d', eval('&iskeyword'))
end)
it('recognizes a trailing comma with +=', function()
command('set wildignore=*.png,')
command('set wildignore+=*.jpg')
eq('*.png,*.jpg', eval('&wildignore'))
end)
end)