Mercurial > vim
comparison src/testdir/test_perl.vim @ 10922:2cc7e86bdada v8.0.0350
patch 8.0.0350: not enough test coverage for Perl
commit https://github.com/vim/vim/commit/ae177b716626c8d517b7c6c7d77f8b1aec6ba5f9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 23 13:45:57 2017 +0100
patch 8.0.0350: not enough test coverage for Perl
Problem: Not enough test coverage for Perl.
Solution: Add more Perl tests. (Dominique Perl, closes https://github.com/vim/vim/issues/1500)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 23 Feb 2017 14:00:05 +0100 |
parents | 4267f8904d47 |
children | 1c4ebbae41d2 |
comparison
equal
deleted
inserted
replaced
10921:fadad6b4cb18 | 10922:2cc7e86bdada |
---|---|
24 normal j | 24 normal j |
25 .perldo s|\n|/|g | 25 .perldo s|\n|/|g |
26 call assert_equal('abc/def/', getline('$')) | 26 call assert_equal('abc/def/', getline('$')) |
27 endfunc | 27 endfunc |
28 | 28 |
29 fu <SID>catch_peval(expr) | 29 func Test_buffer_Delete() |
30 new | |
31 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']) | |
32 perl $curbuf->Delete(7) | |
33 perl $curbuf->Delete(2, 5) | |
34 perl $curbuf->Delete(10) | |
35 call assert_equal(['a', 'f', 'h'], getline(1, '$')) | |
36 bwipe! | |
37 endfunc | |
38 | |
39 func Test_buffer_Append() | |
40 new | |
41 perl $curbuf->Append(1, '1') | |
42 perl $curbuf->Append(2, '2', '3', '4') | |
43 perl @l = ('5' ..'7') | |
44 perl $curbuf->Append(0, @l) | |
45 call assert_equal(['5', '6', '7', '', '1', '2', '3', '4'], getline(1, '$')) | |
46 bwipe! | |
47 endfunc | |
48 | |
49 func Test_buffer_Set() | |
50 new | |
51 call setline(1, ['1', '2', '3', '4', '5']) | |
52 perl $curbuf->Set(2, 'a', 'b', 'c') | |
53 perl $curbuf->Set(4, 'A', 'B', 'C') | |
54 call assert_equal(['1', 'a', 'b', 'A', 'B'], getline(1, '$')) | |
55 bwipe! | |
56 endfunc | |
57 | |
58 func Test_buffer_Get() | |
59 new | |
60 call setline(1, ['1', '2', '3', '4']) | |
61 call assert_equal('2:3', perleval('join(":", $curbuf->Get(2, 3))')) | |
62 bwipe! | |
63 endfunc | |
64 | |
65 func Test_buffer_Count() | |
66 new | |
67 call setline(1, ['a', 'b', 'c']) | |
68 call assert_equal(3, perleval('$curbuf->Count()')) | |
69 bwipe! | |
70 endfunc | |
71 | |
72 func Test_buffer_Name() | |
73 new | |
74 call assert_equal('', perleval('$curbuf->Name()')) | |
75 bwipe! | |
76 new Xfoo | |
77 call assert_equal('Xfoo', perleval('$curbuf->Name()')) | |
78 bwipe! | |
79 endfunc | |
80 | |
81 func Test_buffer_Number() | |
82 call assert_equal(bufnr('%'), perleval('$curbuf->Number()')) | |
83 endfunc | |
84 | |
85 func Test_window_Cursor() | |
86 new | |
87 call setline(1, ['line1', 'line2']) | |
88 perl $curwin->Cursor(2, 3) | |
89 call assert_equal('2:3', perleval('join(":", $curwin->Cursor())')) | |
90 " Col is numbered from 0 in Perl, and from 1 in Vim script. | |
91 call assert_equal([0, 2, 4, 0], getpos('.')) | |
92 bwipe! | |
93 endfunc | |
94 | |
95 func Test_window_SetHeight() | |
96 new | |
97 perl $curwin->SetHeight(2) | |
98 call assert_equal(2, winheight(0)) | |
99 bwipe! | |
100 endfunc | |
101 | |
102 func Test_VIM_Windows() | |
103 new | |
104 " VIM::Windows() without argument in scalar and list context. | |
105 perl $winnr = VIM::Windows() | |
106 perl @winlist = VIM::Windows() | |
107 perl $curbuf->Append(0, $winnr, scalar(@winlist)) | |
108 call assert_equal(['2', '2', ''], getline(1, '$')) | |
109 | |
110 " VIM::Windows() with window number argument. | |
111 perl VIM::Windows(VIM::Eval('winnr()'))->Buffer()->Set(1, 'bar') | |
112 call assert_equal('bar', getline(1)) | |
113 bwipe! | |
114 endfunc | |
115 | |
116 func Test_VIM_Buffers() | |
117 new Xbar | |
118 " VIM::Buffers() without argument in scalar and list context. | |
119 perl $nbuf = VIM::Buffers() | |
120 perl @buflist = VIM::Buffers() | |
121 | |
122 " VIM::Buffers() with argument. | |
123 perl $mybuf = (VIM::Buffers('Xbar'))[0] | |
124 perl $mybuf->Append(0, $nbuf, scalar(@buflist)) | |
125 call assert_equal(['2', '2', ''], getline(1, '$')) | |
126 bwipe! | |
127 endfunc | |
128 | |
129 func <SID>catch_peval(expr) | |
30 try | 130 try |
31 call perleval(a:expr) | 131 call perleval(a:expr) |
32 catch | 132 catch |
33 return v:exception | 133 return v:exception |
34 endtry | 134 endtry |
35 call assert_true(0, 'no exception for `perleval("'.a:expr.'")`') | 135 call assert_true(0, 'no exception for `perleval("'.a:expr.'")`') |
36 return '' | 136 return '' |
37 endfunc | 137 endfunc |
38 | 138 |
39 function Test_perleval() | 139 func Test_perleval() |
40 call assert_false(perleval('undef')) | 140 call assert_false(perleval('undef')) |
41 | 141 |
42 " scalar | 142 " scalar |
43 call assert_equal(0, perleval('0')) | 143 call assert_equal(0, perleval('0')) |
44 call assert_equal(2, perleval('2')) | 144 call assert_equal(2, perleval('2')) |
73 | 173 |
74 call assert_equal('*VIM', perleval('"*VIM"')) | 174 call assert_equal('*VIM', perleval('"*VIM"')) |
75 call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)') | 175 call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)') |
76 endfunc | 176 endfunc |
77 | 177 |
78 function Test_perldo() | 178 func Test_perldo() |
79 sp __TEST__ | 179 sp __TEST__ |
80 exe 'read ' g:testname | 180 exe 'read ' g:testname |
81 perldo s/perl/vieux_chameau/g | 181 perldo s/perl/vieux_chameau/g |
82 1 | 182 1 |
83 call assert_false(search('\Cperl')) | 183 call assert_false(search('\Cperl')) |
97 call assert_equal(wincount + 1, winnr('$')) | 197 call assert_equal(wincount + 1, winnr('$')) |
98 bwipe! | 198 bwipe! |
99 bwipe! | 199 bwipe! |
100 endfunc | 200 endfunc |
101 | 201 |
102 function Test_VIM_package() | 202 func Test_VIM_package() |
103 perl VIM::DoCommand('let l:var = "foo"') | 203 perl VIM::DoCommand('let l:var = "foo"') |
104 call assert_equal(l:var, 'foo') | 204 call assert_equal(l:var, 'foo') |
105 | 205 |
106 set noet | 206 set noet |
107 perl VIM::SetOption('et') | 207 perl VIM::SetOption('et') |
108 call assert_true(&et) | 208 call assert_true(&et) |
109 endfunc | 209 endfunc |
110 | 210 |
111 function Test_stdio() | 211 func Test_stdio() |
112 redir =>l:out | 212 redir =>l:out |
113 perl <<EOF | 213 perl <<EOF |
114 VIM::Msg("&VIM::Msg"); | 214 VIM::Msg("&VIM::Msg"); |
115 print "STDOUT"; | 215 print "STDOUT"; |
116 print STDERR "STDERR"; | 216 print STDERR "STDERR"; |
117 EOF | 217 EOF |
118 redir END | 218 redir END |
119 call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) | 219 call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) |
120 endfunc | 220 endfunc |
121 | 221 |
122 function Test_SvREFCNT() | 222 func Test_SvREFCNT() |
123 new t | 223 new t |
124 perl <<--perl | 224 perl <<--perl |
125 my ($b, $w); | 225 my ($b, $w); |
126 $b = $curbuf for 0 .. 10; | 226 $b = $curbuf for 0 .. 10; |
127 $w = $curwin for 0 .. 10; | 227 $w = $curwin for 0 .. 10; |