annotate src/testdir/test_perl.vim @ 7655:94f34dc2f254 v7.4.1127

commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 17 22:05:48 2016 +0100 patch 7.4.1127 Problem: Both old and new style tests for Perl. Solution: Merge the old tests with the new style tests.
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jan 2016 22:15:04 +0100
parents c7575b07de98
children 54a380c74547
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7651
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for Perl interface
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('perl')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 end
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
7655
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
7 func Test_change_buffer()
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
8 call setline(line('$'), ['1 line 1'])
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
9 perl VIM::DoCommand("normal /^1\n")
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
10 perl $curline = VIM::Eval("line('.')")
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
11 perl $curbuf->Set($curline, "1 changed line 1")
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
12 call assert_equal('1 changed line 1', getline('$'))
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
13 endfunc
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
14
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
15 func Test_evaluate_list()
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
16 call setline(line('$'), ['2 line 2'])
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
17 perl VIM::DoCommand("normal /^2\n")
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
18 perl $curline = VIM::Eval("line('.')")
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
19 let l = ["abc", "def"]
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
20 perl << EOF
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
21 $l = VIM::Eval("l");
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
22 $curbuf->Append($curline, $l);
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
23 EOF
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
24 normal j
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
25 .perldo s|\n|/|g
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
26 call assert_equal('abc/def/', getline('$'))
94f34dc2f254 commit https://github.com/vim/vim/commit/021b593e7ed6c7111cbf189744ad1e5d6c4a7d79
Christian Brabandt <cb@256bit.org>
parents: 7651
diff changeset
27 endfunc
7651
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 fu <SID>catch_peval(expr)
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 try
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call perleval(a:expr)
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 catch
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 return v:exception
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 endtry
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_true(0, 'no exception for `perleval("'.a:expr.'")`')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 return ''
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 endf
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 function Test_perleval()
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call assert_false(perleval('undef'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " scalar
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call assert_equal(0, perleval('0'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call assert_equal(2, perleval('2'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_equal(-2, perleval('-2'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 if has('float')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 call assert_equal(2.5, perleval('2.5'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 else
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 call assert_equal(2, perleval('2.5'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 end
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 sandbox call assert_equal(2, perleval('2'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_equal('abc', perleval('"abc"'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call assert_equal("abc\ndef", perleval('"abc\0def"'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 " ref
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal([], perleval('[]'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 call assert_equal(['word', 42, [42],{}], perleval('["word", 42, [42], {}]'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call assert_equal({}, perleval('{}'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_equal({'foo': 'bar'}, perleval('{foo => "bar"}'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 perl our %h; our @a;
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 let a = perleval('[\(%h, %h, @a, @a)]')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_true((a[0] is a[1]))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call assert_true((a[2] is a[3]))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 perl undef %h; undef @a;
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_true(<SID>catch_peval('{"" , 0}') =~ 'Malformed key Dictionary')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 call assert_true(<SID>catch_peval('{"\0" , 0}') =~ 'Malformed key Dictionary')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 call assert_true(<SID>catch_peval('{"foo\0bar" , 0}') =~ 'Malformed key Dictionary')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call assert_equal('*VIM', perleval('"*VIM"'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 endf
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 function Test_perldo()
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 sp __TEST__
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 exe 'read ' g:testname
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 perldo s/perl/vieux_chameau/g
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 1
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_false(search('\Cperl'))
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 bw!
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 endf
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 function Test_VIM_package()
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 perl VIM::DoCommand('let l:var = "foo"')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 call assert_equal(l:var, 'foo')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 set noet
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 perl VIM::SetOption('et')
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 call assert_true(&et)
c7575b07de98 commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 endf