diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-16 15:59:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-16 15:59:32 +0800 |
commit | 0d9b0fbe579343fa6d6c46e6e1bf6bb8719ea5e0 (patch) | |
tree | b04989c130e1139760f6ccc19236ccf55fc24afa /test/old | |
parent | 54dab9ed9e200f7c5bcac4a8f4901770fa15fa4f (diff) | |
parent | 8a59d04a31725d9038e8c7df30f9b95ea82f9a76 (diff) | |
download | rneovim-0d9b0fbe579343fa6d6c46e6e1bf6bb8719ea5e0.tar.gz rneovim-0d9b0fbe579343fa6d6c46e6e1bf6bb8719ea5e0.tar.bz2 rneovim-0d9b0fbe579343fa6d6c46e6e1bf6bb8719ea5e0.zip |
Merge pull request #23119 from zeertzjq/vim-9.0.0370
vim-patch:9.0.{0370,0379,0390,0397,0411,1446}: :defer and deferred delete
Diffstat (limited to 'test/old')
-rw-r--r-- | test/old/testdir/test_autochdir.vim | 19 | ||||
-rw-r--r-- | test/old/testdir/test_autocmd.vim | 17 | ||||
-rw-r--r-- | test/old/testdir/test_eval_stuff.vim | 64 | ||||
-rw-r--r-- | test/old/testdir/test_quickfix.vim | 22 | ||||
-rw-r--r-- | test/old/testdir/test_user_func.vim | 102 | ||||
-rw-r--r-- | test/old/testdir/test_writefile.vim | 50 |
6 files changed, 217 insertions, 57 deletions
diff --git a/test/old/testdir/test_autochdir.vim b/test/old/testdir/test_autochdir.vim index a8810047a0..652ce8b794 100644 --- a/test/old/testdir/test_autochdir.vim +++ b/test/old/testdir/test_autochdir.vim @@ -30,9 +30,9 @@ func Test_set_filename_other_window() CheckFunction test_autochdir let cwd = getcwd() call test_autochdir() - call mkdir('Xa') - call mkdir('Xb') - call mkdir('Xc') + call mkdir('Xa', 'R') + call mkdir('Xb', 'R') + call mkdir('Xc', 'R') try args Xa/aaa.txt Xb/bbb.txt set acd @@ -44,9 +44,6 @@ func Test_set_filename_other_window() finally set noacd call chdir(cwd) - call delete('Xa', 'rf') - call delete('Xb', 'rf') - call delete('Xc', 'rf') bwipe! aaa.txt bwipe! bbb.txt bwipe! ccc.txt @@ -59,10 +56,10 @@ func Test_acd_win_execute() set acd call test_autochdir() - call mkdir('Xfile') + call mkdir('XacdDir', 'R') let winid = win_getid() - new Xfile/file - call assert_match('testdir.Xfile$', getcwd()) + new XacdDir/file + call assert_match('testdir.XacdDir$', getcwd()) cd .. call assert_match('testdir$', getcwd()) call win_execute(winid, 'echo') @@ -71,7 +68,6 @@ func Test_acd_win_execute() bwipe! set noacd call chdir(cwd) - call delete('Xfile', 'rf') endfunc func Test_verbose_pwd() @@ -82,7 +78,7 @@ func Test_verbose_pwd() edit global.txt call assert_match('\[global\].*testdir$', execute('verbose pwd')) - call mkdir('Xautodir') + call mkdir('Xautodir', 'R') split Xautodir/local.txt lcd Xautodir call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd')) @@ -116,7 +112,6 @@ func Test_verbose_pwd() bwipe! call chdir(cwd) - call delete('Xautodir', 'rf') endfunc func Test_multibyte() diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim index 6d7f1649b3..ec671369f5 100644 --- a/test/old/testdir/test_autocmd.vim +++ b/test/old/testdir/test_autocmd.vim @@ -918,14 +918,13 @@ func Test_BufEnter() call assert_equal('++', g:val) " Also get BufEnter when editing a directory - call mkdir('Xdir') - split Xdir + call mkdir('Xbufenterdir', 'D') + split Xbufenterdir call assert_equal('+++', g:val) " On MS-Windows we can't edit the directory, make sure we wipe the right " buffer. - bwipe! Xdir - call delete('Xdir', 'd') + bwipe! Xbufenterdir au! BufEnter " Editing a "nofile" buffer doesn't read the file but does trigger BufEnter @@ -2186,11 +2185,10 @@ func Test_BufWriteCmd() new file Xbufwritecmd set buftype=acwrite - call mkdir('Xbufwritecmd') + call mkdir('Xbufwritecmd', 'D') write " BufWriteCmd should be triggered even if a directory has the same name call assert_equal(1, g:written) - call delete('Xbufwritecmd', 'd') unlet g:written au! BufWriteCmd bwipe! @@ -2947,16 +2945,15 @@ func Test_throw_in_BufWritePre() endfunc func Test_autocmd_in_try_block() - call mkdir('Xdir') + call mkdir('Xintrydir', 'R') au BufEnter * let g:fname = expand('%') try - edit Xdir/ + edit Xintrydir/ endtry - call assert_match('Xdir', g:fname) + call assert_match('Xintrydir', g:fname) unlet g:fname au! BufEnter - call delete('Xdir', 'rf') endfunc func Test_autocmd_CmdWinEnter() diff --git a/test/old/testdir/test_eval_stuff.vim b/test/old/testdir/test_eval_stuff.vim index 7acc91c17b..20eb873326 100644 --- a/test/old/testdir/test_eval_stuff.vim +++ b/test/old/testdir/test_eval_stuff.vim @@ -36,12 +36,70 @@ func Test_mkdir_p() endtry " 'p' doesn't suppress real errors call writefile([], 'Xfile') - call assert_fails('call mkdir("Xfile", "p")', 'E739') + call assert_fails('call mkdir("Xfile", "p")', 'E739:') call delete('Xfile') call delete('Xmkdir', 'rf') call assert_equal(0, mkdir(v:_null_string)) - call assert_fails('call mkdir([])', 'E730') - call assert_fails('call mkdir("abc", [], [])', 'E745') + call assert_fails('call mkdir([])', 'E730:') + call assert_fails('call mkdir("abc", [], [])', 'E745:') +endfunc + +func DoMkdirDel(name) + call mkdir(a:name, 'pD') + call assert_true(isdirectory(a:name)) +endfunc + +func DoMkdirDelAddFile(name) + call mkdir(a:name, 'pD') + call assert_true(isdirectory(a:name)) + call writefile(['text'], a:name .. '/file') +endfunc + +func DoMkdirDelRec(name) + call mkdir(a:name, 'pR') + call assert_true(isdirectory(a:name)) +endfunc + +func DoMkdirDelRecAddFile(name) + call mkdir(a:name, 'pR') + call assert_true(isdirectory(a:name)) + call writefile(['text'], a:name .. '/file') +endfunc + +func Test_mkdir_defer_del() + " Xtopdir/tmp is created thus deleted, not Xtopdir itself + call mkdir('Xtopdir', 'R') + call DoMkdirDel('Xtopdir/tmp') + call assert_true(isdirectory('Xtopdir')) + call assert_false(isdirectory('Xtopdir/tmp')) + + " Deletion fails because "tmp" contains "sub" + call DoMkdirDel('Xtopdir/tmp/sub') + call assert_true(isdirectory('Xtopdir')) + call assert_true(isdirectory('Xtopdir/tmp')) + call delete('Xtopdir/tmp', 'rf') + + " Deletion fails because "tmp" contains "file" + call DoMkdirDelAddFile('Xtopdir/tmp') + call assert_true(isdirectory('Xtopdir')) + call assert_true(isdirectory('Xtopdir/tmp')) + call assert_true(filereadable('Xtopdir/tmp/file')) + call delete('Xtopdir/tmp', 'rf') + + " Xtopdir/tmp is created thus deleted, not Xtopdir itself + call DoMkdirDelRec('Xtopdir/tmp') + call assert_true(isdirectory('Xtopdir')) + call assert_false(isdirectory('Xtopdir/tmp')) + + " Deletion works even though "tmp" contains "sub" + call DoMkdirDelRec('Xtopdir/tmp/sub') + call assert_true(isdirectory('Xtopdir')) + call assert_false(isdirectory('Xtopdir/tmp')) + + " Deletion works even though "tmp" contains "file" + call DoMkdirDelRecAddFile('Xtopdir/tmp') + call assert_true(isdirectory('Xtopdir')) + call assert_false(isdirectory('Xtopdir/tmp')) endfunc func Test_line_continuation() diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index 838c4b1c15..f720b6e42d 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -6250,28 +6250,6 @@ func Test_very_long_error_line() call setqflist([], 'f') endfunc -" The test depends on deferred delete and string interpolation, which haven't -" been ported, so override it with a rewrite that doesn't use these features. -func! Test_very_long_error_line() - let msg = repeat('abcdefghijklmn', 146) - let emsg = 'Xlonglines.c:1:' . msg - call writefile([msg, emsg], 'Xerror') - cfile Xerror - call delete('Xerror') - cwindow - call assert_equal('|| ' .. msg, getline(1)) - call assert_equal('Xlonglines.c|1| ' .. msg, getline(2)) - cclose - - let l = execute('clist!')->split("\n") - call assert_equal([' 1: ' .. msg, ' 2 Xlonglines.c:1: ' .. msg], l) - - let l = execute('cc')->split("\n") - call assert_equal(['(2 of 2): ' .. msg], l) - - call setqflist([], 'f') -endfunc - " In the quickfix window, spaces at the beginning of an informational line " should not be removed but should be removed from an error line. func Test_info_line_with_space() diff --git a/test/old/testdir/test_user_func.vim b/test/old/testdir/test_user_func.vim index f475803ce1..4bb4078a1c 100644 --- a/test/old/testdir/test_user_func.vim +++ b/test/old/testdir/test_user_func.vim @@ -532,4 +532,106 @@ func Test_funcdef_alloc_failure() bw! endfunc +func AddDefer(arg1, ...) + call extend(g:deferred, [a:arg1]) + if a:0 == 1 + call extend(g:deferred, [a:1]) + endif +endfunc + +func WithDeferTwo() + call extend(g:deferred, ['in Two']) + for nr in range(3) + defer AddDefer('Two' .. nr) + endfor + call extend(g:deferred, ['end Two']) +endfunc + +func WithDeferOne() + call extend(g:deferred, ['in One']) + call writefile(['text'], 'Xfuncdefer') + defer delete('Xfuncdefer') + defer AddDefer('One') + call WithDeferTwo() + call extend(g:deferred, ['end One']) +endfunc + +func WithPartialDefer() + call extend(g:deferred, ['in Partial']) + let Part = funcref('AddDefer', ['arg1']) + defer Part("arg2") + call extend(g:deferred, ['end Partial']) +endfunc + +func Test_defer() + let g:deferred = [] + call WithDeferOne() + + call assert_equal(['in One', 'in Two', 'end Two', 'Two2', 'Two1', 'Two0', 'end One', 'One'], g:deferred) + unlet g:deferred + + call assert_equal('', glob('Xfuncdefer')) + + call assert_fails('defer delete("Xfuncdefer")->Another()', 'E488:') + call assert_fails('defer delete("Xfuncdefer").member', 'E488:') + + let g:deferred = [] + call WithPartialDefer() + call assert_equal(['in Partial', 'end Partial', 'arg1', 'arg2'], g:deferred) + unlet g:deferred + + let Part = funcref('AddDefer', ['arg1'], {}) + call assert_fails('defer Part("arg2")', 'E1300:') +endfunc + +func DeferLevelTwo() + call writefile(['text'], 'XDeleteTwo', 'D') + throw 'someerror' +endfunc + +" def DeferLevelOne() +func DeferLevelOne() + call writefile(['text'], 'XDeleteOne', 'D') + call g:DeferLevelTwo() +" enddef +endfunc + +func Test_defer_throw() + let caught = 'no' + try + call DeferLevelOne() + catch /someerror/ + let caught = 'yes' + endtry + call assert_equal('yes', caught) + call assert_false(filereadable('XDeleteOne')) + call assert_false(filereadable('XDeleteTwo')) +endfunc + +func Test_defer_quitall() + let lines =<< trim END + " vim9script + func DeferLevelTwo() + call writefile(['text'], 'XQuitallTwo', 'D') + qa! + endfunc + + " def DeferLevelOne() + func DeferLevelOne() + call writefile(['text'], 'XQuitallOne', 'D') + call DeferLevelTwo() + " enddef + endfunc + + " DeferLevelOne() + call DeferLevelOne() + END + call writefile(lines, 'XdeferQuitall', 'D') + let res = system(GetVimCommandClean() .. ' -X -S XdeferQuitall') + call assert_equal(0, v:shell_error) + call assert_false(filereadable('XQuitallOne')) + call assert_false(filereadable('XQuitallTwo')) +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_writefile.vim b/test/old/testdir/test_writefile.vim index 6019cee193..312d45e18f 100644 --- a/test/old/testdir/test_writefile.vim +++ b/test/old/testdir/test_writefile.vim @@ -924,19 +924,49 @@ endfunc " Test for ':write ++bin' and ':write ++nobin' func Test_write_binary_file() " create a file without an eol/eof character - call writefile(0z616161, 'Xfile1', 'b') - new Xfile1 - write ++bin Xfile2 - write ++nobin Xfile3 - call assert_equal(0z616161, readblob('Xfile2')) + call writefile(0z616161, 'Xwbfile1', 'b') + new Xwbfile1 + write ++bin Xwbfile2 + write ++nobin Xwbfile3 + call assert_equal(0z616161, readblob('Xwbfile2')) if has('win32') - call assert_equal(0z6161610D.0A, readblob('Xfile3')) + call assert_equal(0z6161610D.0A, readblob('Xwbfile3')) else - call assert_equal(0z6161610A, readblob('Xfile3')) + call assert_equal(0z6161610A, readblob('Xwbfile3')) endif - call delete('Xfile1') - call delete('Xfile2') - call delete('Xfile3') + call delete('Xwbfile1') + call delete('Xwbfile2') + call delete('Xwbfile3') +endfunc + +func DoWriteDefer() + call writefile(['some text'], 'XdeferDelete', 'D') + call assert_equal(['some text'], readfile('XdeferDelete')) +endfunc + +" def DefWriteDefer() +" writefile(['some text'], 'XdefdeferDelete', 'D') +" assert_equal(['some text'], readfile('XdefdeferDelete')) +" enddef + +func Test_write_with_deferred_delete() + call DoWriteDefer() + call assert_equal('', glob('XdeferDelete')) + " call DefWriteDefer() + " call assert_equal('', glob('XdefdeferDelete')) +endfunc + +func DoWriteFile() + call writefile(['text'], 'Xthefile', 'D') + cd .. +endfunc + +func Test_write_defer_delete_chdir() + let dir = getcwd() + call DoWriteFile() + call assert_notequal(dir, getcwd()) + call chdir(dir) + call assert_equal('', glob('Xthefile')) endfunc " Check that buffer is written before triggering QuitPre |