From af23d173883f47fd02a9a380c719e4428370b484 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 7 Mar 2023 04:13:04 +0100 Subject: test: move oldtests to test directory (#22536) The new oldtest directory is in test/old/testdir. The reason for this is that many tests have hardcoded the parent directory name to be 'testdir'. --- test/old/testdir/test_bufline.vim | 296 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 test/old/testdir/test_bufline.vim (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim new file mode 100644 index 0000000000..0468025f55 --- /dev/null +++ b/test/old/testdir/test_bufline.vim @@ -0,0 +1,296 @@ +" Tests for setbufline(), getbufline(), appendbufline(), deletebufline() + +source shared.vim +source screendump.vim +source check.vim + +func Test_setbufline_getbufline() + " similar to Test_set_get_bufline() + new + let b = bufnr('%') + hide + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal('foo', getbufoneline(b, 1)) + call assert_equal(['bar'], getbufline(b, '$')) + call assert_equal('bar', getbufoneline(b, '$')) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bd!" b + call assert_equal([], getbufline(b, 1, 2)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + let b = bufnr('%') + wincmd w + + call assert_equal(1, setbufline(b, 5, 'x')) + call assert_equal(1, setbufline(b, 5, ['x'])) + call assert_equal(1, setbufline(b, 5, [])) + call assert_equal(1, setbufline(b, 5, v:_null_list)) + + call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, v:_null_list->setbufline(bufnr('$') + 1, 1)) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + + call assert_equal(0, setbufline(b, 4, ['d', 'e'])) + call assert_equal(['c'], b->getbufline(3)) + call assert_equal('c', b->getbufoneline(3)) + call assert_equal(['d'], getbufline(b, 4)) + call assert_equal('d', getbufoneline(b, 4)) + call assert_equal(['e'], getbufline(b, 5)) + call assert_equal('e', getbufoneline(b, 5)) + call assert_equal([], getbufline(b, 6)) + call assert_equal([], getbufline(b, 2, 1)) + + if has('job') + call setbufline(b, 2, [function('eval'), #{key: 123}, test_null_job()]) + call assert_equal(["function('eval')", + \ "{'key': 123}", + \ "no process"], + \ getbufline(b, 2, 4)) + endif + exe "bwipe! " . b +endfunc + +func Test_setbufline_getbufline_fold() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + +func Test_setbufline_getbufline_fold_tab() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + tab new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + +func Test_setline_startup() + let cmd = GetVimCommand('Xscript') + if cmd == '' + return + endif + call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') + call system(cmd) + call assert_equal(['Hello'], readfile('Xtest')) + + call delete('Xscript') + call delete('Xtest') +endfunc + +func Test_appendbufline() + new + let b = bufnr('%') + hide + + new + call setline(1, ['line1', 'line2', 'line3']) + normal! 2gggg + call assert_equal(2, line("''")) + + call assert_equal(0, appendbufline(b, 0, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + call assert_equal(0, appendbufline(b, 0, 'baz')) + call assert_equal(['baz', 'foo', 'bar'], getbufline(b, 1, 3)) + + " appendbufline() in a hidden buffer shouldn't move marks in current window. + call assert_equal(2, line("''")) + bwipe! + + exe "bd!" b + call assert_equal([], getbufline(b, 1, 3)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + let b = bufnr('%') + wincmd w + + call assert_equal(1, appendbufline(b, -1, 'x')) + call assert_equal(1, appendbufline(b, -1, ['x'])) + call assert_equal(1, appendbufline(b, -1, [])) + call assert_equal(1, appendbufline(b, -1, v:_null_list)) + + call assert_equal(1, appendbufline(b, 4, 'x')) + call assert_equal(1, appendbufline(b, 4, ['x'])) + call assert_equal(1, appendbufline(b, 4, [])) + call assert_equal(1, appendbufline(b, 4, v:_null_list)) + + call assert_equal(1, appendbufline(1234, 1, 'x')) + call assert_equal(1, appendbufline(1234, 1, ['x'])) + call assert_equal(1, appendbufline(1234, 1, [])) + call assert_equal(1, appendbufline(1234, 1, v:_null_list)) + + call assert_equal(0, appendbufline(b, 1, [])) + call assert_equal(0, appendbufline(b, 1, v:_null_list)) + call assert_equal(1, appendbufline(b, 3, [])) + call assert_equal(1, appendbufline(b, 3, v:_null_list)) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + + call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) + call assert_equal(['c'], getbufline(b, 3)) + call assert_equal(['d'], getbufline(b, 4)) + call assert_equal(['e'], getbufline(b, 5)) + call assert_equal([], getbufline(b, 6)) + exe "bwipe! " . b +endfunc + +func Test_deletebufline() + new + let b = bufnr('%') + call setline(1, ['aaa', 'bbb', 'ccc']) + hide + + new + call setline(1, ['line1', 'line2', 'line3']) + normal! 2gggg + call assert_equal(2, line("''")) + + call assert_equal(0, deletebufline(b, 2)) + call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2)) + call assert_equal(0, deletebufline(b, 2, 8)) + call assert_equal(['aaa'], getbufline(b, 1, 2)) + + " deletebufline() in a hidden buffer shouldn't move marks in current window. + call assert_equal(2, line("''")) + bwipe! + + exe "bd!" b + call assert_equal(1, b->deletebufline(1)) + + call assert_equal(1, deletebufline(-1, 1)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + call cursor(line('$'), 1) + let b = bufnr('%') + wincmd w + call assert_equal(1, deletebufline(b, 4)) + call assert_equal(0, deletebufline(b, 1)) + call assert_equal(['b', 'c'], getbufline(b, 1, 2)) + exe "bwipe! " . b + + edit XbufOne + let one = bufnr() + call setline(1, ['a', 'b', 'c']) + setlocal nomodifiable + split XbufTwo + let two = bufnr() + call assert_fails('call deletebufline(one, 1)', 'E21:') + call assert_equal(two, bufnr()) + bwipe! XbufTwo + bwipe! XbufOne +endfunc + +func Test_appendbufline_redraw() + CheckScreendump + + let lines =<< trim END + new foo + let winnr = 'foo'->bufwinnr() + let buf = bufnr('foo') + wincmd p + call appendbufline(buf, '$', range(1,200)) + exe winnr .. 'wincmd w' + norm! G + wincmd p + call deletebufline(buf, 1, '$') + call appendbufline(buf, '$', 'Hello Vim world...') + END + call writefile(lines, 'XscriptMatchCommon') + let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) + + call StopVimInTerminal(buf) + call delete('XscriptMatchCommon') +endfunc + +func Test_setbufline_select_mode() + new + call setline(1, ['foo', 'bar']) + call feedkeys("j^v2l\", 'nx') + + let bufnr = bufadd('Xdummy') + call bufload(bufnr) + call setbufline(bufnr, 1, ['abc']) + + call feedkeys("x", 'nx') + call assert_equal(['foo', 'x'], getline(1, 2)) + + exe "bwipe! " .. bufnr + bwipe! +endfunc + +func Test_deletebufline_select_mode() + new + call setline(1, ['foo', 'bar']) + call feedkeys("j^v2l\", 'nx') + + let bufnr = bufadd('Xdummy') + call bufload(bufnr) + call setbufline(bufnr, 1, ['abc', 'def']) + call deletebufline(bufnr, 1) + + call feedkeys("x", 'nx') + call assert_equal(['foo', 'x'], getline(1, 2)) + + exe "bwipe! " .. bufnr + bwipe! +endfunc + +func Test_setbufline_startup_nofile() + let before =<< trim [CODE] + set shortmess+=F + file Xresult + set buftype=nofile + call setbufline('', 1, 'success') + [CODE] + let after =<< trim [CODE] + set buftype= + write + quit + [CODE] + + if !RunVim(before, after, '--clean') + return + endif + call assert_equal(['success'], readfile('Xresult')) + call delete('Xresult') +endfunc + +" Test that setbufline(), appendbufline() and deletebufline() should fail and +" return 1 when "textlock" is active. +func Test_change_bufline_with_textlock() + new + inoremap setbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('1', getline(1)) + inoremap appendbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('11', getline(1)) + inoremap deletebufline('', 1) + call assert_fails("normal a\", 'E565:') + call assert_equal('111', getline(1)) + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From ff801ce7f728ea51cec3328328ac41d98d545725 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 14:59:52 +0800 Subject: vim-patch:8.2.0533: tests using term_wait() can still be flaky Problem: Tests using term_wait() can still be flaky. Solution: Increase the wait time when rerunning a test. (James McCoy, closes vim/vim#5899) Halve the initial times to make tests run faster when there is no rerun. https://github.com/vim/vim/commit/6a2c5a7dd5c9215cc030d5ea6e4616d782c091dd Co-authored-by: Bram Moolenaar --- test/old/testdir/test_bufline.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index 0468025f55..7431576f6b 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -217,7 +217,7 @@ func Test_appendbufline_redraw() END call writefile(lines, 'XscriptMatchCommon') let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) - call term_wait(buf) + call TermWait(buf) call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) call StopVimInTerminal(buf) -- cgit From 02ca31979bed2b7e432401b23aaf7987a3f0badb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 15:38:19 +0800 Subject: vim-patch:8.2.4339: CTRL-A does not work properly with the cmdline popup menu Problem: CTRL-A does not work properly with the cmdline popup menu. Solution: Fix issues with CTRL-A. Add more tests for the cmdline popup menu. Remove TermWait() before VeriryScreenDump(). Refactor the cmdline popup code. (Yegappan Lakshmanan, closes vim/vim#9735) https://github.com/vim/vim/commit/560dff49c0095111fc96b4b8dd7f4d269aba9473 Co-authored-by: Yegappan Lakshmanan --- test/old/testdir/test_bufline.vim | 1 - 1 file changed, 1 deletion(-) (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index 7431576f6b..50feaf2689 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -217,7 +217,6 @@ func Test_appendbufline_redraw() END call writefile(lines, 'XscriptMatchCommon') let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) - call TermWait(buf) call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) call StopVimInTerminal(buf) -- cgit From c170708023149221e5364a72094aa9ab94bfe8cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Aug 2023 17:44:04 +0800 Subject: vim-patch:9.0.0391: using separate delete() call instead of writefile() 'D' flag Problem: Using separate delete() call instead of writefile() 'D' flag. Solution: Use the writefile 'D' flag. https://github.com/vim/vim/commit/3411265a3698c3d5ef56d9b0c3bb237a9f5fdba1 Co-authored-by: Bram Moolenaar --- test/old/testdir/test_bufline.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index 50feaf2689..51b657f00e 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -86,11 +86,10 @@ func Test_setline_startup() if cmd == '' return endif - call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') + call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript', 'D') call system(cmd) call assert_equal(['Hello'], readfile('Xtest')) - call delete('Xscript') call delete('Xtest') endfunc @@ -215,12 +214,11 @@ func Test_appendbufline_redraw() call deletebufline(buf, 1, '$') call appendbufline(buf, '$', 'Hello Vim world...') END - call writefile(lines, 'XscriptMatchCommon') + call writefile(lines, 'XscriptMatchCommon', 'D') let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10}) call VerifyScreenDump(buf, 'Test_appendbufline_1', {}) call StopVimInTerminal(buf) - call delete('XscriptMatchCommon') endfunc func Test_setbufline_select_mode() -- cgit From 10990eace23fa7eef39203359dca8f9cde1dcc90 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Aug 2023 17:45:44 +0800 Subject: vim-patch:9.0.0415: on MS-Windows some tests are flaky Problem: On MS-Windows some tests are flaky. Solution: Add sleeps, disable swapfile, mark test as flaky. (Ken Takata, closes vim/vim#11082) https://github.com/vim/vim/commit/0500e87eba7b2a82392dbb5d573de19f8ff138e7 Co-authored-by: K.Takata --- test/old/testdir/test_bufline.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index 51b657f00e..bbf1d02079 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -88,6 +88,7 @@ func Test_setline_startup() endif call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript', 'D') call system(cmd) + sleep 50m call assert_equal(['Hello'], readfile('Xtest')) call delete('Xtest') -- cgit From 09910d5b35f2432a22374e59560a1bbd08907d57 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Aug 2023 18:21:15 +0800 Subject: vim-patch:9.0.0837: append() reports failure when not appending anything Problem: append() reports failure when not appending anything. Solution: Only report failure when appending something. (closes vim/vim#11498) https://github.com/vim/vim/commit/cd9c8d400c1eb9cbb4ff6a33be02f91a30ab13b2 Co-authored-by: Bram Moolenaar --- test/old/testdir/test_bufline.vim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test/old/testdir/test_bufline.vim') diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index bbf1d02079..29ec46a606 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -25,8 +25,8 @@ func Test_setbufline_getbufline() call assert_equal(1, setbufline(b, 5, 'x')) call assert_equal(1, setbufline(b, 5, ['x'])) - call assert_equal(1, setbufline(b, 5, [])) - call assert_equal(1, setbufline(b, 5, v:_null_list)) + call assert_equal(0, setbufline(b, 5, [])) + call assert_equal(0, setbufline(b, 5, v:_null_list)) call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) @@ -91,6 +91,11 @@ func Test_setline_startup() sleep 50m call assert_equal(['Hello'], readfile('Xtest')) + call assert_equal(0, setline(1, [])) + call assert_equal(0, setline(1, v:_null_list)) + call assert_equal(0, setline(5, [])) + call assert_equal(0, setline(6, v:_null_list)) + call delete('Xtest') endfunc @@ -130,8 +135,8 @@ func Test_appendbufline() call assert_equal(1, appendbufline(b, 4, 'x')) call assert_equal(1, appendbufline(b, 4, ['x'])) - call assert_equal(1, appendbufline(b, 4, [])) - call assert_equal(1, appendbufline(b, 4, v:_null_list)) + call assert_equal(0, appendbufline(b, 4, [])) + call assert_equal(0, appendbufline(b, 4, v:_null_list)) call assert_equal(1, appendbufline(1234, 1, 'x')) call assert_equal(1, appendbufline(1234, 1, ['x'])) @@ -140,8 +145,8 @@ func Test_appendbufline() call assert_equal(0, appendbufline(b, 1, [])) call assert_equal(0, appendbufline(b, 1, v:_null_list)) - call assert_equal(1, appendbufline(b, 3, [])) - call assert_equal(1, appendbufline(b, 3, v:_null_list)) + call assert_equal(0, appendbufline(b, 3, [])) + call assert_equal(0, appendbufline(b, 3, v:_null_list)) call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) -- cgit