From 84569693e109f322ed77948ce74c19af5f04b527 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 14 Aug 2018 06:14:46 -0400 Subject: vim-patch:8.0.1209: still too many old style tests Problem: Still too many old style tests. Solution: Convert a few more tests to new style. (Yegappan Lakshmanan, closes vim/vim#2230) https://github.com/vim/vim/commit/53f0c962394dc6bc66d5b0762af9434e672d1b25 --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_join.vim | 35 ++++++++++++++ src/nvim/testdir/test_user_func.vim | 96 +++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 src/nvim/testdir/test_join.vim create mode 100644 src/nvim/testdir/test_user_func.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 361db47fc7..1e3dc04049 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -114,6 +114,7 @@ NEW_TESTS ?= \ test_timers.res \ test_undo.res \ test_usercommands.res \ + test_user_func.res \ test_vimscript.res \ test_visual.res \ test_winbuf_close.res \ diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 238dbe8d90..ace4b377cb 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -19,6 +19,7 @@ source test_functions.vim source test_ga.vim source test_global.vim source test_goto.vim +source test_join.vim source test_jumps.vim source test_fileformat.vim source test_filetype.vim diff --git a/src/nvim/testdir/test_join.vim b/src/nvim/testdir/test_join.vim new file mode 100644 index 0000000000..1c97414164 --- /dev/null +++ b/src/nvim/testdir/test_join.vim @@ -0,0 +1,35 @@ +" Test for joining lines. + +func Test_join_with_count() + new + call setline(1, ['one', 'two', 'three', 'four']) + normal J + call assert_equal('one two', getline(1)) + %del + call setline(1, ['one', 'two', 'three', 'four']) + normal 10J + call assert_equal('one two three four', getline(1)) + quit! +endfunc + +" Tests for setting the '[,'] marks when joining lines. +func Test_join_marks() + enew + call append(0, [ + \ "\t\tO sodales, ludite, vos qui", + \ "attamen consulite per voster honur. Tua pulchra " . + \ "facies me fay planszer milies", + \ "", + \ "This line.", + \ "Should be joined with the next line", + \ "and with this line"]) + + normal gg0gqj + call assert_equal([0, 1, 1, 0], getpos("'[")) + call assert_equal([0, 2, 1, 0], getpos("']")) + + /^This line/;'}-join + call assert_equal([0, 4, 11, 0], getpos("'[")) + call assert_equal([0, 4, 67, 0], getpos("']")) + enew! +endfunc diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim new file mode 100644 index 0000000000..e7a3701386 --- /dev/null +++ b/src/nvim/testdir/test_user_func.vim @@ -0,0 +1,96 @@ +" Test for user functions. +" Also test an mapping calling a function. +" Also test that a builtin function cannot be replaced. +" Also test for regression when calling arbitrary expression. + +func Table(title, ...) + let ret = a:title + let idx = 1 + while idx <= a:0 + exe "let ret = ret . a:" . idx + let idx = idx + 1 + endwhile + return ret +endfunc + +func Compute(n1, n2, divname) + if a:n2 == 0 + return "fail" + endif + exe "let g:" . a:divname . " = ". a:n1 / a:n2 + return "ok" +endfunc + +func Expr1() + silent! normal! v + return "111" +endfunc + +func Expr2() + call search('XX', 'b') + return "222" +endfunc + +func ListItem() + let g:counter += 1 + return g:counter . '. ' +endfunc + +func ListReset() + let g:counter = 0 + return '' +endfunc + +func FuncWithRef(a) + unlet g:FuncRef + return a:a +endfunc + +func Test_user_func() + let g:FuncRef=function("FuncWithRef") + let g:counter = 0 + inoremap ( ListItem() + inoremap [ ListReset() + imap + Expr1() + imap * Expr2() + let g:retval = "nop" + + call assert_equal('xxx4asdf', Table("xxx", 4, "asdf")) + call assert_equal('fail', Compute(45, 0, "retval")) + call assert_equal('nop', g:retval) + call assert_equal('ok', Compute(45, 5, "retval")) + call assert_equal(9, g:retval) + call assert_equal(333, g:FuncRef(333)) + + enew + + normal oXX+-XX + call assert_equal('XX111-XX', getline('.')) + normal o---*--- + call assert_equal('---222---', getline('.')) + normal o(one + call assert_equal('1. one', getline('.')) + normal o(two + call assert_equal('2. two', getline('.')) + normal o[(one again + call assert_equal('1. one again', getline('.')) + + call assert_equal(3, max([1, 2, 3])) + call assert_fails("call extend(g:, {'max': function('min')})", 'E704') + call assert_equal(3, max([1, 2, 3])) + + " Regression: the first line below used to throw ?E110: Missing ')'? + " Second is here just to prove that this line is correct when not skipping + " rhs of &&. + call assert_equal(0, (0 && (function('tr'))(1, 2, 3))) + call assert_equal(1, (1 && (function('tr'))(1, 2, 3))) + + delfunc Table + delfunc Compute + delfunc Expr1 + delfunc Expr2 + delfunc ListItem + delfunc ListReset + unlet g:retval g:counter + enew! +endfunc -- cgit From 5e38ff105c20bc3920e840046f6af651c99f186c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 14 Aug 2018 10:18:08 -0400 Subject: vim-patch:8.0.1218: writing to freed memory in autocmd Problem: Writing to freed memory in autocmd. Solution: Make a copy of the tag line. (Dominique Pelle, closes vim/vim#2245) https://github.com/vim/vim/commit/8d84ff1a3c8cfe59399d3f675ec080066582fdb6 --- src/nvim/testdir/test_autocmd.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index e4ab3ccea8..10fea4dad3 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -248,6 +248,24 @@ func Test_augroup_warning() au! VimEnter endfunc +func Test_BufReadCmdHelp() + " This used to cause access to free memory + au BufReadCmd * e +h + help + + helpclose + au! BufReadCmd +endfunc + +func Test_BufReadCmdHelpJump() + " This used to cause access to free memory + au BufReadCmd * e +h{ + help + + helpclose + au! BufReadCmd +endfunc + func Test_augroup_deleted() " This caused a crash before E936 was introduced augroup x -- cgit From 1daf2cb0eaa21a88656332eec4a2dbf8b824c634 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 14 Aug 2018 11:22:42 -0400 Subject: vim-patch:8.0.1488: emacs tags no longer work Problem: Emacs tags no longer work. (zdohnal) Solution: Do not skip over end of line. https://github.com/vim/vim/commit/0d2073773218736e368786f0db7024bd9b9e7912 --- src/nvim/testdir/test_tagjump.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 268a153077..f9bd8b5246 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -230,4 +230,32 @@ func Test_tag_file_encoding() call delete('Xtags1') endfunc +func Test_tagjump_etags() + if !has('emacs_tags') + return + endif + call writefile([ + \ "void foo() {}", + \ "int main(int argc, char **argv)", + \ "{", + \ "\tfoo();", + \ "\treturn 0;", + \ "}", + \ ], 'Xmain.c') + + call writefile([ + \ "\x0c", + \ "Xmain.c,64", + \ "void foo() {}\x7ffoo\x011,0", + \ "int main(int argc, char **argv)\x7fmain\x012,14", + \ ], 'Xtags') + set tags=Xtags + ta foo + call assert_equal('void foo() {}', getline('.')) + + call delete('Xtags') + call delete('Xmain.c') + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 8e2a892e709df140d321b8058be041c0fe111ebc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 14 Aug 2018 11:59:09 -0400 Subject: vim-patch:8.0.1409: buffer overflow in :tags command Problem: Buffer overflow in :tags command. Solution: Use vim_snprintf(). (Dominique Pelle, closes vim/vim#2471, closes vim/vim#2475) Add a test. https://github.com/vim/vim/commit/132f75255ecea17ff621f71236568c5d8d8e0163 --- src/nvim/testdir/test_taglist.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index 2d1557ebd9..3ad2025915 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -1,4 +1,4 @@ -" test 'taglist' function +" test 'taglist' function and :tags command func Test_taglist() call writefile([ @@ -56,3 +56,8 @@ func Test_taglist_ctags_etags() call delete('Xtags') endfunc + +func Test_tags_too_long() + call assert_fails('tag ' . repeat('x', 1020), 'E426') + tags +endfunc -- cgit From 0bdd4e8393636ad7c7d013df4c361264b1c048f1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 14 Aug 2018 18:19:56 -0400 Subject: oldtests: finish port of 8.0.1224 --- src/nvim/testdir/test_autocmd.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 10fea4dad3..e0f55b79c1 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -253,16 +253,15 @@ func Test_BufReadCmdHelp() au BufReadCmd * e +h help - helpclose au! BufReadCmd endfunc func Test_BufReadCmdHelpJump() " This used to cause access to free memory au BufReadCmd * e +h{ - help + " } to fix highlighting + call assert_fails('help', 'E434:') - helpclose au! BufReadCmd endfunc -- cgit From ee37a0c79ae61931b15570ed1877779dc7bd0dad Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 15 Aug 2018 00:27:03 -0400 Subject: vim-patch:8.0.1413: accessing freed memory in :cbuffer Problem: Accessing freed memory in :cbuffer. Solution: Get quickfix list after executing autocmds. (closes vim/vim#2470) https://github.com/vim/vim/commit/aaf6e43b7a99cedb89d73ba749a46f7a0f16bbb6 --- src/nvim/testdir/test_autocmd.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index e0f55b79c1..7173558d50 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1182,6 +1182,13 @@ func Test_nocatch_wipe_dummy_buffer() au! endfunc +func Test_wipe_cbuffer() + sv x + au * * bw + lb + au! +endfunc + " Test TextChangedI and TextChangedP func Test_ChangedP() " Nvim does not support test_override(). -- cgit From a0938e068f99b56a3474fd739f1a3f52240d28f7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 15 Aug 2018 01:13:38 -0400 Subject: vim-patch:8.0.1633: a TextChanged autocmd triggers when it is defined Problem: A TextChanged autocmd triggers when it is defined after creating a buffer. Solution: Set b_last_changedtick when opening a buffer. (Hirohito Highlight, closes vim/vim#2742) https://github.com/vim/vim/commit/8c64a36e40b8746404f7151abe6849393396af10 --- src/nvim/testdir/test_autocmd.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 7173558d50..b1502eff89 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1,5 +1,7 @@ " Tests for autocommands +source shared.vim + func! s:cleanup_buffers() abort for bnr in range(1, bufnr('$')) if bufloaded(bnr) && bufnr('%') != bnr @@ -1269,3 +1271,22 @@ func Test_TextChangedI_with_setline() call test_override('starting', 0) bwipe! endfunc + +func Test_Changed_FirstTime() + if !has('terminal') || has('gui_running') + return + endif + " Prepare file for TextChanged event. + call writefile([''], 'Xchanged.txt') + let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) + call assert_equal('running', term_getstatus(buf)) + " It's only adding autocmd, so that no event occurs. + call term_sendkeys(buf, ":au! TextChanged call writefile(['No'], 'Xchanged.txt')\") + call term_sendkeys(buf, "\\:qa!\") + call WaitFor({-> term_getstatus(buf) == 'finished'}) + call assert_equal([''], readfile('Xchanged.txt')) + + " clean up + call delete('Xchanged.txt') + bwipe! +endfunc -- cgit