diff options
-rw-r--r-- | src/nvim/testdir/test_perl.vim | 102 |
1 files changed, 94 insertions, 8 deletions
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 <SID>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(<SID>catch_peval('{"" , 0}') =~ 'Malformed key Dictionary') + " call assert_true(<SID>catch_peval('{"\0" , 0}') =~ 'Malformed key Dictionary') + " call assert_true(<SID>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 <<EOF + VIM::Msg("&VIM::Msg"); + print "STDOUT"; + print STDERR "STDERR"; +EOF + redir END + call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) +endfunc + +" Run first to get a clean namespace +func Test_000_SvREFCNT() + throw 'skipped: TODO: ' + for i in range(8) + exec 'new X'.i + endfor + new t + perl <<--perl +#line 5 "Test_000_SvREFCNT()" + my ($b, $w); + + my $num = 0; + for ( 0 .. 100 ) { + if ( ++$num >= 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 |