From a86295cd5c2bf15a11eb05e226fd8e226154f6a6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:26:17 +0800 Subject: [PATCH] vim-patch:8.2.0615: regexp benchmark stest is old style (#20940) Problem: Regexp benchmark stest is old style. Solution: Make it a new style test. Fix using a NULL list. Add more tests. (Yegappan Lakshmanan, closes vim/vim#5963) https://github.com/vim/vim/commit/ad48e6c1590842ab6d48e6caba3e9250734dae27 N/A patches: vim-patch:9.0.0829: wrong counts in macro comment --- src/nvim/eval.c | 8 +++++ src/nvim/testdir/test_autocmd.vim | 2 ++ src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_bufline.vim | 31 +++++++++++++++++++ src/nvim/testdir/test_cmdline.vim | 5 +++ src/nvim/testdir/test_functions.vim | 25 +++++++++++++++ src/nvim/testdir/test_tagjump.vim | 1 + src/nvim/testdir/test_window_cmd.vim | 12 +++++++ ..._freeze_spec.lua => bench_regexp_spec.lua} | 10 +++--- test/functional/vimscript/null_spec.lua | 2 +- 10 files changed, 91 insertions(+), 6 deletions(-) rename test/benchmark/{bench_re_freeze_spec.lua => bench_regexp_spec.lua} (92%) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index bc669a3e11..37da475e59 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5581,6 +5581,13 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T const char *line = NULL; if (lines->v_type == VAR_LIST) { l = lines->vval.v_list; + if (l == NULL || tv_list_len(l) == 0) { + // set proper return code + if (lnum > curbuf->b_ml.ml_line_count) { + rettv->vval.v_number = 1; // FAIL + } + goto done; + } li = tv_list_first(l); } else { line = tv_get_string_chk(lines); @@ -5651,6 +5658,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T update_topline(curwin); } +done: if (!is_curbuf) { curbuf = curbuf_save; curwin = curwin_save; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 8c15249f97..a3534cea87 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -533,6 +533,8 @@ func Test_augroup_warning() redir END call assert_notmatch("W19:", res) au! VimEnter + + call assert_fails('augroup!', 'E471:') endfunc func Test_BufReadCmdHelp() diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 1c0261933f..046acb81e1 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -303,6 +303,7 @@ func Test_blob_index() call assert_equal(3, index(0z11110111, 0x11, -2)) call assert_equal(0, index(0z11110111, 0x11, -10)) call assert_fails("echo index(0z11110111, 0x11, [])", 'E745:') + call assert_equal(-1, index(v:_null_blob, 1)) call assert_fails('call index("asdf", 0)', 'E897:') endfunc diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 5a47f8ef25..2867f13cbc 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -19,8 +19,19 @@ func Test_setbufline_getbufline() 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(['d'], getbufline(b, 4)) @@ -84,9 +95,29 @@ func Test_appendbufline() 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)) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 27ac91e49f..3e5fe06c90 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1270,6 +1270,11 @@ func Test_verbosefile() let log = readfile('Xlog') call assert_match("foo\nbar", join(log, "\n")) call delete('Xlog') + call mkdir('Xdir') + if !has('win32') " FIXME: no error on Windows, libuv bug? + call assert_fails('set verbosefile=Xdir', 'E474:') + endif + call delete('Xdir', 'd') endfunc func Test_verbose_option() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 5718266dae..1ba0cf9080 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -798,18 +798,41 @@ func Test_mode() delfunction OperatorFunc endfunc +" Test for append() func Test_append() enew! split call append(0, ["foo"]) + call append(1, []) + call append(1, v:_null_list) + call assert_equal(['foo', ''], getline(1, '$')) split only undo + undo " Using $ instead of '$' must give an error call assert_fails("call append($, 'foobar')", 'E116:') endfunc +" Test for setline() +func Test_setline() + new + call setline(0, ["foo"]) + call setline(0, []) + call setline(0, v:_null_list) + call setline(1, ["bar"]) + call setline(1, []) + call setline(1, v:_null_list) + call setline(2, []) + call setline(2, v:_null_list) + call setline(3, []) + call setline(3, v:_null_list) + call setline(2, ["baz"]) + call assert_equal(['bar', 'baz'], getline(1, '$')) + close! +endfunc + func Test_getbufvar() let bnr = bufnr('%') let b:var_num = '1234' @@ -917,6 +940,7 @@ func Test_match_func() call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) call assert_equal(4, match('testing', 'ing', -1)) call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') + call assert_equal(-1, match(v:_null_list, 2)) endfunc func Test_matchend() @@ -1922,6 +1946,7 @@ func Test_call() call assert_equal(3, 'len'->call([123])) call assert_fails("call call('len', 123)", 'E714:') call assert_equal(0, call('', [])) + call assert_equal(0, call('len', v:_null_list)) function Mylen() dict return len(self.data) diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 592e13e340..f3ca5e306b 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -372,6 +372,7 @@ func Test_getsettagstack() call assert_fails("call settagstack(1, {'items' : 10})", 'E714') call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E928') call assert_fails("call settagstack(1, {'items' : []}, 'b')", 'E962') + call assert_equal(-1, settagstack(0, v:_null_dict)) set tags=Xtags call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index c7b5896082..20564fed66 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1142,6 +1142,18 @@ func Test_split_cmds_with_no_room() call Run_noroom_for_newwindow_test('v') endfunc +" Test for various wincmd failures +func Test_wincmd_fails() + only! + call assert_beeps("normal \w") + call assert_beeps("normal \p") + call assert_beeps("normal \gk") + call assert_beeps("normal \r") + call assert_beeps("normal \K") + call assert_beeps("normal \H") + call assert_beeps("normal \2gt") +endfunc + func Test_window_resize() " Vertical :resize (absolute, relative, min and max size). vsplit diff --git a/test/benchmark/bench_re_freeze_spec.lua b/test/benchmark/bench_regexp_spec.lua similarity index 92% rename from test/benchmark/bench_re_freeze_spec.lua rename to test/benchmark/bench_regexp_spec.lua index abd97f8aa8..903af5f574 100644 --- a/test/benchmark/bench_re_freeze_spec.lua +++ b/test/benchmark/bench_regexp_spec.lua @@ -1,4 +1,4 @@ --- Test for benchmarking RE engine. +-- Test for benchmarking the RE engine. local helpers = require('test.functional.helpers')(after_each) local insert, source = helpers.insert, helpers.source @@ -13,13 +13,13 @@ local sample_file = 'src/nvim/testdir/samples/re.freeze.txt' local measure_cmd = [[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@