From 32baed519ccfe0c1134167505f29600414b71f02 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 12 Oct 2020 22:24:26 -0400 Subject: vim-patch:8.2.0573: using :version twice leaks memory Problem: using :version twice leaks memory Solution: Only initialize variables once. (Dominique Pelle, closes vim/vim#5917) https://github.com/vim/vim/commit/278e83863b2c7329f6712b8809e4aa5e6a50e13f Cherry-pick test_alot.vim change from patch v8.2.0164 so that test_expr.vim and test_version.vim do not conflict. Cherry-pick modeline from patch v8.2.1432. N/A patches for version.c: vim-patch:8.1.0103: long version string cannot be translated Problem: Long version string cannot be translated. Solution: Build the string in init_longVersion(). https://github.com/vim/vim/commit/35fb6fbf727c72eb5987a1556bbba26dca14cc48 vim-patch:8.1.0975: using STRNCPY() wrongly. Warning for uninitialized variable Problem: Using STRNCPY() wrongly. Warning for uninitialized variable. Solution: Use mch_memmove(). Initialize variable. (Yasuhiro Matsumoto, closes vim/vim#3979) https://github.com/vim/vim/commit/c666388367282c3c7d1d7af24883cfa0d40b046e vim-patch:8.1.1403: cannot build without the timer feature Problem: Cannot build without the timer feature. Solution: Add #ifdef. https://github.com/vim/vim/commit/35d5af6c0b618aef9ca87b05b2e184934e47d916 vim-patch:8.1.1569: cannot build with signs but without diff feature Problem: Cannot build with signs but without diff feature. Solution: Move #ifdef. (Tom Ryder) https://github.com/vim/vim/commit/bf8c3adef21c24a9bf2c1a93042a096ea8d8b2e1 vim-patch:8.1.1856: popup preview test fails sometimes Problem: popup preview test fails sometimes. (Christian Brabandt) Solution: Clear the command line. https://github.com/vim/vim/commit/78d629a38548115a68298081d39d6d90708af561 vim-patch:8.1.1983: compiler nags for uninitialized variable and unused function Problem: Compiler nags for uninitialized variable and unused function. Solution: Add unnecessary initialization. Move function inside #ifdef. https://github.com/vim/vim/commit/ea781459b9617aa47335061fcc78403495260315 vim-patch:8.1.2014: terminal altscreen test fails sometimes Problem: Terminal altscreen test fails sometimes. Solution: Use WaitFor(). https://github.com/vim/vim/commit/b9c79cf5cc876ba4d46d938ad4a15800dbe45e64 vim-patch:8.1.2365: missing tests for recent popupwin changes Problem: Missing tests for recent popupwin changes. Solution: Add test cases. https://github.com/vim/vim/commit/20ebbeac461ffc2a5e5dbfbb0ba380b8854615bd vim-patch:8.1.2406: leaking memory in test_paste and test_registers Problem: Leaking memory in test_paste and test_registers. Solution: Free the old title. Don't copy expr_line. https://github.com/vim/vim/commit/6b649ac4fd0cbf88c5a05d82ad151d0ce980916a vim-patch:8.2.0616: build error when disabling the diff feature Problem: Build error when disabling the diff feature. Solution: Move parenthesis outside of #ifdef. (Tom Ryder) https://github.com/vim/vim/commit/e770598f31ad88fc98e40ead4b228ebc04afaa5d vim-patch:8.2.1020: popupwin test fails in the GUI Problem: Popupwin test fails in the GUI. Solution: Send GUI byte sequence for . https://github.com/vim/vim/commit/b326edf5b30813b2ccdee3ac07ee6495ca5187ff vim-patch:8.2.1036: popupwin test fails sometimes Problem: Popupwin test fails sometimes. Solution: Use WaitForAssert() instead of a sleep. https://github.com/vim/vim/commit/373c65104e0991724cb57910dfb3e5c276e2d7e7 vim-patch:8.2.1038: popupwin test fails Problem: Popupwin test fails. Solution: Fix WaitForAssert() argument. https://github.com/vim/vim/commit/b2b218d89b3a6f450e65afd5e59ac234a5fa1eb7 vim-patch:8.2.1743: cannot build without the eval feature Problem: Cannot build without the eval feature. Solution: Move shorten_dir outside of #ifdef. https://github.com/vim/vim/commit/273af497cac345897cf6369baa87a070876a5815 vim-patch:8.2.1843: Netbeans: with huge buffer number memory allocation may fail Problem: Netbeans: with huge buffer number memory allocation may fail. Solution: Check for size overflow. https://github.com/vim/vim/commit/b9616af23f31fc18721a92643c21f42b69854efe --- src/nvim/testdir/test_alot.vim | 2 +- src/nvim/testdir/test_version.vim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/nvim/testdir/test_version.vim (limited to 'src') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 5668f45dea..7647475427 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -13,7 +13,6 @@ source test_ex_undo.vim source test_ex_z.vim source test_execute_func.vim source test_expand_func.vim -source test_expr.vim source test_feedkeys.vim source test_filter_cmd.vim source test_filter_map.vim @@ -50,6 +49,7 @@ source test_tagjump.vim source test_taglist.vim source test_true_false.vim source test_unlet.vim +source test_version.vim source test_virtualedit.vim source test_window_cmd.vim source test_wnext.vim diff --git a/src/nvim/testdir/test_version.vim b/src/nvim/testdir/test_version.vim new file mode 100644 index 0000000000..46cf34979f --- /dev/null +++ b/src/nvim/testdir/test_version.vim @@ -0,0 +1,12 @@ +" Test :version Ex command + +func Test_version() + " version should always return the same string. + let v1 = execute('version') + let v2 = execute('version') + call assert_equal(v1, v2) + + call assert_match("^\n\nNVIM v[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+.*", v1) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 01dff1fbfb7aa8afea3ac60da25d47e073c63005 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 12 Oct 2020 23:04:53 -0400 Subject: vim-patch:8.2.0957: compiler warning for uninitialized variable Problem: Compiler warning for uninitialized variable. (Tony Mechelynck) Solution: Initialize one variable. https://github.com/vim/vim/commit/2d4070d3b02e775a6f3d5ef52265add270e09a4f --- src/nvim/spell.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index f036d7fe04..1984a357c3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -396,8 +396,7 @@ size_t spell_check( mi.mi_word = ptr; mi.mi_fend = ptr; if (spell_iswordp(mi.mi_fend, wp)) { - int prev_upper; - int this_upper; + bool this_upper = false; // init for gcc if (use_camel_case) { c = PTR2CHAR(mi.mi_fend); @@ -407,7 +406,7 @@ size_t spell_check( do { MB_PTR_ADV(mi.mi_fend); if (use_camel_case) { - prev_upper = this_upper; + const bool prev_upper = this_upper; c = PTR2CHAR(mi.mi_fend); this_upper = SPELL_ISUPPER(c); camel_case = !prev_upper && this_upper; -- cgit From b946bcbc3b191e11a392af38217876ad1bf50e87 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 13 Oct 2020 18:58:58 -0400 Subject: vim-patch:8.2.1842: crash when USE_FNAME_CASE is defined and using :browse Problem: Crash when USE_FNAME_CASE is defined and using :browse. Solution: Don't use read-only memory for ".". (Yegappan Lakshmanan, closes vim/vim#7123) https://github.com/vim/vim/commit/21cbe175eece17fad21d7403b00422445b587138 --- src/nvim/testdir/test_edit.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index d4b1c63741..caebc341e0 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1559,3 +1559,23 @@ func Test_edit_is_a_directory() call delete(dirname, 'rf') endfunc + +func Test_edit_browse() + " in the GUI this opens a file picker, we only test the terminal behavior + CheckNotGui + + " ":browse xxx" checks for the FileExplorer augroup and assumes editing "." + " works then. + augroup FileExplorer + au! + augroup END + + " When the USE_FNAME_CASE is defined this used to cause a crash. + browse enew + bwipe! + + browse split + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From bddd67a331334b12a32d93f6b43f39e9ec120f2d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 13 Oct 2020 21:31:08 -0400 Subject: vim-patch:8.1.0095: dialog for ":browse tabnew" says "new window" Problem: Dialog for ":browse tabnew" says "new window". Solution: Use "new tab page". (closes vim/vim#3053) https://github.com/vim/vim/commit/39902a06d92750c203d86c921b9d69995f949d97 --- src/nvim/ex_docmd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 3f4ad321e3..b4c634292c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6929,8 +6929,9 @@ void ex_splitview(exarg_T *eap) { win_T *old_curwin = curwin; char_u *fname = NULL; - - + const bool use_tab = eap->cmdidx == CMD_tabedit + || eap->cmdidx == CMD_tabfind + || eap->cmdidx == CMD_tabnew; /* A ":split" in the quickfix window works like ":new". Don't want two * quickfix windows. But it's OK when doing ":tab split". */ @@ -6952,9 +6953,7 @@ void ex_splitview(exarg_T *eap) /* * Either open new tab page or split the window. */ - if (eap->cmdidx == CMD_tabedit - || eap->cmdidx == CMD_tabfind - || eap->cmdidx == CMD_tabnew) { + if (use_tab) { if (win_new_tabpage(cmdmod.tab != 0 ? cmdmod.tab : eap->addr_count == 0 ? 0 : (int)eap->line2 + 1, eap->arg) != FAIL) { do_exedit(eap, old_curwin); -- cgit From 3d2cd647443c38d9d284b57a573b8d3fb7cb48c1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 13 Oct 2020 21:57:21 -0400 Subject: vim-patch:8.2.0710: Netbeans test sometimes fails Problem: Netbeans test sometimes fails. Solution: Mark any test using an external command as flaky. https://github.com/vim/vim/commit/4a070cc82e00618db279526797564cb2b4e9b060 --- src/nvim/testdir/shared.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index 9bc037a59f..4f1ddcd7b9 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -56,6 +56,9 @@ endfunc " Run "cmd". Returns the job if using a job. func RunCommand(cmd) + " Running an external command can occasionally be slow or fail. + let g:test_is_flaky = 1 + let job = 0 if has('job') let job = job_start(a:cmd, {"stoponexit": "hup"}) -- cgit From e396eb549e984b4f9db663e07a71c6de53d424b3 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 14 Oct 2020 02:49:22 -0400 Subject: vim-patch:8.1.0978: blob not tested with Perl Problem: Blob not tested with Perl. Solution: Add more test coverage. Fixes a crash. (Dominique Pelle, closes vim/vim#4037) https://github.com/vim/vim/commit/2472ae81dff8c30f5d63db8ad2c937deae8be646 This commit is only to match test_perl.vim from Vim 8.1.0978 so that test_perl.vim patches are easier to port. --- src/nvim/testdir/test_perl.vim | 102 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_perl.vim b/src/nvim/testdir/test_perl.vim index 2343f389fa..872194a804 100644 --- a/src/nvim/testdir/test_perl.vim +++ b/src/nvim/testdir/test_perl.vim @@ -4,6 +4,7 @@ if !has('perl') || has('win32') finish endif +" FIXME: RunTest don't see any error when Perl abort... perl $SIG{__WARN__} = sub { die "Unexpected warnings from perl: @_" }; func Test_change_buffer() @@ -23,11 +24,15 @@ func Test_evaluate_list() $l = VIM::Eval("l"); $curbuf->Append($curline, $l); EOF + normal j + .perldo s|\n|/|g + " call assert_equal('abc/def/', getline('$')) + call assert_equal('def', getline('$')) endfunc funct Test_VIM_Blob() call assert_equal('0z', perleval('VIM::Blob("")')) - "call assert_equal('0z31326162', 'VIM::Blob("12ab")'->perleval()) + call assert_equal('0z31326162', perleval('VIM::Blob("12ab")')) call assert_equal('0z00010203', perleval('VIM::Blob("\x00\x01\x02\x03")')) call assert_equal('0z8081FEFF', perleval('VIM::Blob("\x80\x81\xfe\xff")')) endfunc @@ -46,7 +51,6 @@ func Test_buffer_Append() new perl $curbuf->Append(1, '1') perl $curbuf->Append(2, '2', '3', '4') - call assert_equal(['', '1', '2', '3', '4'], getline(1, '$')) perl @l = ('5' ..'7') perl $curbuf->Append(0, @l) call assert_equal(['5', '6', '7', '', '1', '2', '3', '4'], getline(1, '$')) @@ -114,7 +118,7 @@ func Test_VIM_Windows() perl $curbuf->Append(0, $winnr, scalar(@winlist)) call assert_equal(['2', '2', ''], getline(1, '$')) - "" VIM::Windows() with window number argument. + " VIM::Windows() with window number argument. perl (VIM::Windows(VIM::Eval('winnr()')))[0]->Buffer()->Set(1, 'bar') call assert_equal('bar', getline(1)) bwipe! @@ -133,10 +137,20 @@ func Test_VIM_Buffers() bwipe! endfunc +func catch_peval(expr) + try + call perleval(a:expr) + catch + return v:exception + endtry + call assert_report('no exception for `perleval("'.a:expr.'")`') + return '' +endfunc + func Test_perleval() call assert_false(perleval('undef')) - "" scalar + " scalar call assert_equal(0, perleval('0')) call assert_equal(2, perleval('2')) call assert_equal(-2, perleval('-2')) @@ -146,9 +160,12 @@ func Test_perleval() call assert_equal(2, perleval('2.5')) end + " sandbox call assert_equal(2, perleval('2')) + call assert_equal('abc', perleval('"abc"')) + " call assert_equal("abc\ndef", perleval('"abc\0def"')) - "" ref + " ref call assert_equal([], perleval('[]')) call assert_equal(['word', 42, [42],{}], perleval('["word", 42, [42], {}]')) @@ -156,13 +173,19 @@ func Test_perleval() call assert_equal({'foo': 'bar'}, perleval('{foo => "bar"}')) perl our %h; our @a; - let a = perleval('[\%h, \%h, \@a, \@a]') - echo a + let a = perleval('[\(%h, %h, @a, @a)]') + " call assert_true((a[0] is a[1])) call assert_equal(a[0], a[1]) + " call assert_true((a[2] is a[3])) call assert_equal(a[2], a[3]) perl undef %h; undef @a; + " call assert_true(catch_peval('{"" , 0}') =~ 'Malformed key Dictionary') + " call assert_true(catch_peval('{"\0" , 0}') =~ 'Malformed key Dictionary') + " call assert_true(catch_peval('{"foo\0bar" , 0}') =~ 'Malformed key Dictionary') + call assert_equal('*VIM', perleval('"*VIM"')) + " call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)') endfunc func Test_perldo() @@ -179,7 +202,7 @@ func Test_perldo() perldo VIM::DoCommand("%d_") bwipe! - "" Check switching to another buffer does not trigger ml_get error. + " Check switching to another buffer does not trigger ml_get error. new let wincount = winnr('$') call setline(1, ['one', 'two', 'three']) @@ -198,6 +221,69 @@ func Test_VIM_package() call assert_true(&et) endfunc +func Test_stdio() + throw 'skipped: TODO: ' + redir =>l:out + perl <= 8 ) { $num = 0 } + VIM::DoCommand("buffer X$num"); + $b = $curbuf; + } + + VIM::DoCommand("buffer t"); + + $b = $curbuf for 0 .. 100; + $w = $curwin for 0 .. 100; + () = VIM::Buffers for 0 .. 100; + () = VIM::Windows for 0 .. 100; + + VIM::DoCommand('bw! t'); + if (exists &Internals::SvREFCNT) { + my $cb = Internals::SvREFCNT($$b); + my $cw = Internals::SvREFCNT($$w); + VIM::Eval("assert_equal(2, $cb, 'T1')"); + VIM::Eval("assert_equal(2, $cw, 'T2')"); + my $strongref; + foreach ( VIM::Buffers, VIM::Windows ) { + VIM::DoCommand("%bw!"); + my $c = Internals::SvREFCNT($_); + VIM::Eval("assert_equal(2, $c, 'T3')"); + $c = Internals::SvREFCNT($$_); + next if $c == 2 && !$strongref++; + VIM::Eval("assert_equal(1, $c, 'T4')"); + } + $cb = Internals::SvREFCNT($$curbuf); + $cw = Internals::SvREFCNT($$curwin); + VIM::Eval("assert_equal(3, $cb, 'T5')"); + VIM::Eval("assert_equal(3, $cw, 'T6')"); + } + VIM::Eval("assert_false($$b)"); + VIM::Eval("assert_false($$w)"); +--perl + %bw! +endfunc + func Test_set_cursor() " Check that setting the cursor position works. new -- cgit From 4543af9d53bc5a222a7ac01e17e2ad8a8ed63c8e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 14 Oct 2020 17:44:14 -0400 Subject: vim-patch:8.1.0221: not enough testing for the Ruby interface Problem: Not enough testing for the Ruby interface. Solution: Add more tests. (Dominique Pelle, closes vim/vim#3252) https://github.com/vim/vim/commit/edd6aacb010ad2402fc98f19e7f6b7c29ba2656f Modified some tests to make them pass for Neovim. Some tests will always fail because +ruby is externalized in Neovim. Skip failing ruby tests for now. --- src/nvim/testdir/test_ruby.vim | 357 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 324 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_ruby.vim b/src/nvim/testdir/test_ruby.vim index 64199570a9..00b362a9ec 100644 --- a/src/nvim/testdir/test_ruby.vim +++ b/src/nvim/testdir/test_ruby.vim @@ -4,6 +4,13 @@ if !has('ruby') finish end +" Helper function as there is no builtin rubyeval() function similar +" to perleval, luaevel() or pyeval(). +func RubyEval(ruby_expr) + let s = split(execute('ruby print ' . a:ruby_expr), "\n") + return (len(s) == 0) ? '' : s[-1] +endfunc + func Test_ruby_change_buffer() call setline(line('$'), ['1 line 1']) ruby Vim.command("normal /^1\n") @@ -11,37 +18,6 @@ func Test_ruby_change_buffer() call assert_equal('1 changed line 1', getline('$')) endfunc -func Test_ruby_evaluate_list() - throw 'skipped: TODO: ' - call setline(line('$'), ['2 line 2']) - ruby Vim.command("normal /^2\n") - let l = ["abc", "def"] - ruby << EOF - curline = $curbuf.line_number - l = Vim.evaluate("l"); - $curbuf.append(curline, l.join("\n")) -EOF - normal j - .rubydo $_ = $_.gsub(/\n/, '/') - call assert_equal('abc/def', getline('$')) -endfunc - -func Test_ruby_evaluate_dict() - let d = {'a': 'foo', 'b': 123} - redir => l:out - ruby d = Vim.evaluate("d"); print d - redir END - call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n")) -endfunc - -func Test_ruby_evaluate_special_var() - let l = [v:true, v:false, v:null] - redir => l:out - ruby d = Vim.evaluate("l"); print d - redir END - call assert_equal(['[true, false, nil]'], split(l:out, "\n")) -endfunc - func Test_rubydo() throw 'skipped: TODO: ' " Check deleting lines does not trigger ml_get error. @@ -56,8 +32,7 @@ func Test_rubydo() call setline(1, ['one', 'two', 'three']) rubydo Vim.command("new") call assert_equal(wincount + 1, winnr('$')) - bwipe! - bwipe! + %bwipe! endfunc func Test_rubyfile() @@ -75,8 +50,324 @@ func Test_set_cursor() normal gg rubydo $curwin.cursor = [1, 5] call assert_equal([1, 6], [line('.'), col('.')]) + call assert_equal('[1, 5]', RubyEval('$curwin.cursor')) " Check that movement after setting cursor position keeps current column. normal j call assert_equal([2, 6], [line('.'), col('.')]) + call assert_equal('[2, 5]', RubyEval('$curwin.cursor')) + + " call assert_fails('ruby $curwin.cursor = [1]', + " \ 'ArgumentError: array length must be 2') + bwipe! +endfunc + +" Test buffer.count and buffer.length (number of lines in buffer) +func Test_buffer_count() + new + call setline(1, ['one', 'two', 'three']) + call assert_equal('3', RubyEval('$curbuf.count')) + call assert_equal('3', RubyEval('$curbuf.length')) + bwipe! +endfunc + +" Test buffer.name (buffer name) +func Test_buffer_name() + new Xfoo + call assert_equal(expand('%:p'), RubyEval('$curbuf.name')) + bwipe + call assert_equal('', RubyEval('$curbuf.name')) +endfunc + +" Test buffer.number (number of the buffer). +func Test_buffer_number() + new + call assert_equal(string(bufnr('%')), RubyEval('$curbuf.number')) + new + call assert_equal(string(bufnr('%')), RubyEval('$curbuf.number')) + + %bwipe +endfunc + +" Test buffer.delete({n}) (delete line {n}) +func Test_buffer_delete() + new + call setline(1, ['one', 'two', 'three']) + ruby $curbuf.delete(2) + call assert_equal(['one', 'three'], getline(1, '$')) + + " call assert_fails('ruby $curbuf.delete(0)', 'IndexError: line number 0 out of range') + " call assert_fails('ruby $curbuf.delete(3)', 'IndexError: line number 3 out of range') + call assert_fails('ruby $curbuf.delete(3)', 'RuntimeError: Index out of bounds') + + bwipe! +endfunc + +" Test buffer.append({str}, str) (append line {str} after line {n}) +func Test_buffer_append() + new + ruby $curbuf.append(0, 'one') + ruby $curbuf.append(1, 'three') + ruby $curbuf.append(1, 'two') + ruby $curbuf.append(4, 'four') + + call assert_equal(['one', 'two', 'three', '', 'four'], getline(1, '$')) + + " call assert_fails('ruby $curbuf.append(-1, "x")', + " \ 'IndexError: line number -1 out of range') + call assert_fails('ruby $curbuf.append(-1, "x")', + \ 'ArgumentError: Index out of bounds') + call assert_fails('ruby $curbuf.append(6, "x")', + \ 'RuntimeError: Index out of bounds') + + bwipe! +endfunc + +" Test buffer.line (get or set the current line) +func Test_buffer_line() + new + call setline(1, ['one', 'two', 'three']) + 2 + call assert_equal('two', RubyEval('$curbuf.line')) + + ruby $curbuf.line = 'TWO' + call assert_equal(['one', 'TWO', 'three'], getline(1, '$')) + + bwipe! +endfunc + +" Test buffer.line_number (get current line number) +func Test_buffer_line_number() + new + call setline(1, ['one', 'two', 'three']) + 2 + call assert_equal('2', RubyEval('$curbuf.line_number')) + + bwipe! +endfunc + +func Test_buffer_get() + new + call setline(1, ['one', 'two']) + call assert_equal('one', RubyEval('$curbuf[1]')) + call assert_equal('two', RubyEval('$curbuf[2]')) + + " call assert_fails('ruby $curbuf[0]', + " \ 'IndexError: line number 0 out of range') + call assert_fails('ruby $curbuf[3]', + \ 'RuntimeError: Index out of bounds') + + bwipe! +endfunc + +func Test_buffer_set() + new + call setline(1, ['one', 'two']) + ruby $curbuf[2] = 'TWO' + ruby $curbuf[1] = 'ONE' + + " call assert_fails('ruby $curbuf[0] = "ZERO"', + " \ 'IndexError: line number 0 out of range') + " call assert_fails('ruby $curbuf[3] = "THREE"', + " \ 'IndexError: line number 3 out of range') + call assert_fails('ruby $curbuf[3] = "THREE"', + \ 'RuntimeError: Index out of bounds') + bwipe! +endfunc + +" Test window.width (get or set window height). +func Test_window_height() + new + + " Test setting window height + ruby $curwin.height = 2 + call assert_equal(2, winheight(0)) + + " Test getting window height + call assert_equal('2', RubyEval('$curwin.height')) + + bwipe +endfunc + +" Test window.width (get or set window width). +func Test_window_width() + vnew + + " Test setting window width + ruby $curwin.width = 2 + call assert_equal(2, winwidth(0)) + + " Test getting window width + call assert_equal('2', RubyEval('$curwin.width')) + + bwipe +endfunc + +" Test window.buffer (get buffer object of a window object). +func Test_window_buffer() + new Xfoo1 + new Xfoo2 + ruby $b2 = $curwin.buffer + ruby $w2 = $curwin + wincmd j + ruby $b1 = $curwin.buffer + ruby $w1 = $curwin + + " call assert_equal(RubyEval('$b1'), RubyEval('$w1.buffer')) + " call assert_equal(RubyEval('$b2'), RubyEval('$w2.buffer')) + call assert_equal(string(bufnr('Xfoo1')), RubyEval('$w1.buffer.number')) + call assert_equal(string(bufnr('Xfoo2')), RubyEval('$w2.buffer.number')) + + ruby $b1, $w1, $b2, $w2 = nil + %bwipe +endfunc + +" Test Vim::Window.current (get current window object) +func Test_Vim_window_current() + let cw = RubyEval('$curwin') + " call assert_equal(cw, RubyEval('Vim::Window.current')) + call assert_match('^#$', cw) +endfunc + +" Test Vim::Window.count (number of windows) +func Test_Vim_window_count() + new Xfoo1 + new Xfoo2 + split + call assert_equal('4', RubyEval('Vim::Window.count')) + %bwipe + call assert_equal('1', RubyEval('Vim::Window.count')) +endfunc + +" Test Vim::Window[n] (get window object of window n) +func Test_Vim_window_get() + new Xfoo1 + new Xfoo2 + call assert_match('Xfoo2$', RubyEval('Vim::Window[0].buffer.name')) + wincmd j + call assert_match('Xfoo1$', RubyEval('Vim::Window[1].buffer.name')) + wincmd j + call assert_equal('', RubyEval('Vim::Window[2].buffer.name')) + %bwipe +endfunc + +" Test Vim::Buffer.current (return the buffer object of current buffer) +func Test_Vim_buffer_current() + let cb = RubyEval('$curbuf') + " call assert_equal(cb, RubyEval('Vim::Buffer.current')) + call assert_match('^#$', cb) +endfunc + +" Test Vim::Buffer:.count (return the number of buffers) +func Test_Vim_buffer_count() + new Xfoo1 + new Xfoo2 + call assert_equal('3', RubyEval('Vim::Buffer.count')) + %bwipe + call assert_equal('1', RubyEval('Vim::Buffer.count')) +endfunc + +" Test Vim::buffer[n] (return the buffer object of buffer number n) +func Test_Vim_buffer_get() + new Xfoo1 + new Xfoo2 + + " Index of Vim::Buffer[n] goes from 0 to the number of buffers. + call assert_equal('', RubyEval('Vim::Buffer[0].name')) + call assert_match('Xfoo1$', RubyEval('Vim::Buffer[1].name')) + call assert_match('Xfoo2$', RubyEval('Vim::Buffer[2].name')) + call assert_fails('ruby print Vim::Buffer[3].name', + \ "NoMethodError: undefined method `name' for nil:NilClass") + %bwipe +endfunc + +" Test Vim::command({cmd}) (execute a Ex command)) +" Test Vim::command({cmd}) +func Test_Vim_command() + new + call setline(1, ['one', 'two', 'three', 'four']) + ruby Vim::command('2,3d') + call assert_equal(['one', 'four'], getline(1, '$')) + bwipe! +endfunc + +" Test Vim::set_option (set a vim option) +func Test_Vim_set_option() + call assert_equal(0, &number) + ruby Vim::set_option('number') + call assert_equal(1, &number) + ruby Vim::set_option('nonumber') + call assert_equal(0, &number) +endfunc + +func Test_Vim_evaluate() + call assert_equal('123', RubyEval('Vim::evaluate("123")')) + " Vim::evaluate("123").class gives Integer or Fixnum depending + " on versions of Ruby. + call assert_match('^Integer\|Fixnum$', RubyEval('Vim::evaluate("123").class')) + + call assert_equal('1.23', RubyEval('Vim::evaluate("1.23")')) + call assert_equal('Float', RubyEval('Vim::evaluate("1.23").class')) + + call assert_equal('foo', RubyEval('Vim::evaluate("\"foo\"")')) + call assert_equal('String', RubyEval('Vim::evaluate("\"foo\"").class')) + + call assert_equal('[1, 2]', RubyEval('Vim::evaluate("[1, 2]")')) + call assert_equal('Array', RubyEval('Vim::evaluate("[1, 2]").class')) + + call assert_equal('{"1"=>2}', RubyEval('Vim::evaluate("{1:2}")')) + call assert_equal('Hash', RubyEval('Vim::evaluate("{1:2}").class')) + + call assert_equal('', RubyEval('Vim::evaluate("v:null")')) + call assert_equal('NilClass', RubyEval('Vim::evaluate("v:null").class')) + + " call assert_equal('', RubyEval('Vim::evaluate("v:none")')) + " call assert_equal('NilClass', RubyEval('Vim::evaluate("v:none").class')) + + call assert_equal('true', RubyEval('Vim::evaluate("v:true")')) + call assert_equal('TrueClass', RubyEval('Vim::evaluate("v:true").class')) + call assert_equal('false', RubyEval('Vim::evaluate("v:false")')) + call assert_equal('FalseClass',RubyEval('Vim::evaluate("v:false").class')) +endfunc + +func Test_Vim_evaluate_list() + call setline(line('$'), ['2 line 2']) + ruby Vim.command("normal /^2\n") + let l = ["abc", "def"] + ruby << EOF + curline = $curbuf.line_number + l = Vim.evaluate("l"); + $curbuf.append(curline, l.join("|")) +EOF + normal j + .rubydo $_ = $_.gsub(/\|/, '/') + call assert_equal('abc/def', getline('$')) +endfunc + +func Test_Vim_evaluate_dict() + let d = {'a': 'foo', 'b': 123} + redir => l:out + ruby d = Vim.evaluate("d"); print d + redir END + call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n")) +endfunc + +" Test Vim::message({msg}) (display message {msg}) +func Test_Vim_message() + throw 'skipped: TODO: ' + ruby Vim::message('A message') + let messages = split(execute('message'), "\n") + call assert_equal('A message', messages[-1]) +endfunc + +func Test_print() + ruby print "Hello World!" + let messages = split(execute('message'), "\n") + call assert_equal('Hello World!', messages[-1]) +endfunc + +func Test_p() + ruby p 'Just a test' + let messages = split(execute('message'), "\n") + call assert_equal('"Just a test"', messages[-1]) endfunc -- cgit From 3183b09a5e0cce78be49e08cffb5208cf424e8c1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 14 Oct 2020 17:50:46 -0400 Subject: vim-patch:8.1.0269: Ruby Kernel.#p method always returns nil Problem: Ruby Kernel.#p method always returns nil. Solution: Copy p method implementation from Ruby code. (Masataka Pocke Kuwabara, closes vim/vim#3315) https://github.com/vim/vim/commit/51e9fbf1c7ab4ec61ac959d72d5d5cb0a0b356bb --- src/nvim/testdir/test_ruby.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_ruby.vim b/src/nvim/testdir/test_ruby.vim index 00b362a9ec..77a42e0a8a 100644 --- a/src/nvim/testdir/test_ruby.vim +++ b/src/nvim/testdir/test_ruby.vim @@ -370,4 +370,17 @@ func Test_p() ruby p 'Just a test' let messages = split(execute('message'), "\n") call assert_equal('"Just a test"', messages[-1]) + + " Check return values of p method + + call assert_equal('123', RubyEval('p(123)')) + call assert_equal('[1, 2, 3]', RubyEval('p(1, 2, 3)')) + + " Avoid the "message maintainer" line. + let $LANG = '' + messages clear + call assert_equal('true', RubyEval('p() == nil')) + + let messages = split(execute('message'), "\n") + call assert_equal(0, len(messages)) endfunc -- cgit