neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit a86295cd5c2bf15a11eb05e226fd8e226154f6a6
parent daf9a63d67254342382cf79f1cd216f8e5722579
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sat,  5 Nov 2022 12:26:17 +0800

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
Diffstat:
Msrc/nvim/eval.c | 8++++++++
Msrc/nvim/testdir/test_autocmd.vim | 2++
Msrc/nvim/testdir/test_blob.vim | 1+
Msrc/nvim/testdir/test_bufline.vim | 31+++++++++++++++++++++++++++++++
Msrc/nvim/testdir/test_cmdline.vim | 5+++++
Msrc/nvim/testdir/test_functions.vim | 25+++++++++++++++++++++++++
Msrc/nvim/testdir/test_tagjump.vim | 1+
Msrc/nvim/testdir/test_window_cmd.vim | 12++++++++++++
Dtest/benchmark/bench_re_freeze_spec.lua | 64----------------------------------------------------------------
Atest/benchmark/bench_regexp_spec.lua | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/functional/vimscript/null_spec.lua | 2+-
11 files changed, 150 insertions(+), 65 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \<C-W>w") + call assert_beeps("normal \<C-W>p") + call assert_beeps("normal \<C-W>gk") + call assert_beeps("normal \<C-W>r") + call assert_beeps("normal \<C-W>K") + call assert_beeps("normal \<C-W>H") + call assert_beeps("normal \<C-W>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_re_freeze_spec.lua @@ -1,64 +0,0 @@ --- Test for benchmarking RE engine. - -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, command = helpers.clear, helpers.command - --- Temporary file for gathering benchmarking results for each regexp engine. -local result_file = 'benchmark.out' --- Fixture containing an HTML fragment that can make a search appear to freeze. -local sample_file = 'src/nvim/testdir/samples/re.freeze.txt' - --- Vim script code that does both the work and the benchmarking of that work. -local measure_cmd = - [[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]] -local measure_script = [[ - func! Measure(re, file, pattern, arg) - let sstart=reltime() - - execute 'set re=' . a:re - execute 'split' a:arg a:file - call search(a:pattern, '', '', 10000) - q! - - $put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart))) - endfunc]] - -describe('regexp search', function() - -- The test cases rely on a temporary result file, which we prepare and write - -- to disk. - setup(function() - clear() - source(measure_script) - insert('" Benchmark_results:') - command('write! ' .. result_file) - end) - - -- At the end of the test run we just print the contents of the result file - -- for human inspection and promptly delete the file. - teardown(function() - print '' - for line in io.lines(result_file) do - print(line) - end - os.remove(result_file) - end) - - it('is working with regexpengine=0', function() - local regexpengine = 0 - command(string.format(measure_cmd, regexpengine)) - command('write') - end) - - it('is working with regexpengine=1', function() - local regexpengine = 1 - command(string.format(measure_cmd, regexpengine)) - command('write') - end) - - it('is working with regexpengine=2', function() - local regexpengine = 2 - command(string.format(measure_cmd, regexpengine)) - command('write') - end) -end) diff --git a/test/benchmark/bench_regexp_spec.lua b/test/benchmark/bench_regexp_spec.lua @@ -0,0 +1,64 @@ +-- Test for benchmarking the RE engine. + +local helpers = require('test.functional.helpers')(after_each) +local insert, source = helpers.insert, helpers.source +local clear, command = helpers.clear, helpers.command + +-- Temporary file for gathering benchmarking results for each regexp engine. +local result_file = 'benchmark.out' +-- Fixture containing an HTML fragment that can make a search appear to freeze. +local sample_file = 'src/nvim/testdir/samples/re.freeze.txt' + +-- Vim script code that does both the work and the benchmarking of that work. +local measure_cmd = + [[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]] +local measure_script = [[ + func Measure(re, file, pattern, arg) + let sstart = reltime() + + execute 'set re=' .. a:re + execute 'split' a:arg a:file + call search(a:pattern, '', '', 10000) + quit! + + $put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart))) + endfunc]] + +describe('regexp search', function() + -- The test cases rely on a temporary result file, which we prepare and write + -- to disk. + setup(function() + clear() + source(measure_script) + insert('" Benchmark_results:') + command('write! ' .. result_file) + end) + + -- At the end of the test run we just print the contents of the result file + -- for human inspection and promptly delete the file. + teardown(function() + print '' + for line in io.lines(result_file) do + print(line) + end + os.remove(result_file) + end) + + it('is working with regexpengine=0', function() + local regexpengine = 0 + command(string.format(measure_cmd, regexpengine)) + command('write') + end) + + it('is working with regexpengine=1', function() + local regexpengine = 1 + command(string.format(measure_cmd, regexpengine)) + command('write') + end) + + it('is working with regexpengine=2', function() + local regexpengine = 2 + command(string.format(measure_cmd, regexpengine)) + command('write') + end) +end) diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua @@ -69,7 +69,7 @@ describe('NULL', function() null_expr_test('can be splice-indexed', 'L[:]', 0, {}) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) - null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() + null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function()