Skip to content

Commit 17fd35a

Browse files
committed
Perlito5 - tests
1 parent 21f1282 commit 17fd35a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

t5-bug/410-ampersand.t

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use feature 'say';
2+
use strict;
3+
4+
say "1..15";
5+
6+
my $v = 0;
7+
my $r = 0;
8+
my $e = '';
9+
10+
sub with_proto () {
11+
if (@_) {
12+
$v += $_[0]
13+
}
14+
else {
15+
$v += 8
16+
}
17+
}
18+
19+
sub no_proto {
20+
if (@_) {
21+
$v += $_[0]
22+
}
23+
else {
24+
$v += 8
25+
}
26+
}
27+
28+
# sanity test with proto
29+
30+
$v = 3;
31+
$r = with_proto + 4;
32+
print "not " if $v != 11;
33+
print "ok 1 - with_proto $v\n";
34+
print "not " if $r != 15;
35+
print "ok 2 - with_proto $r\n";
36+
37+
# sanity test without proto
38+
39+
$v = 3;
40+
$r = no_proto + 4;
41+
print "not " if $v != 7;
42+
print "ok 3 - no_proto $v\n";
43+
print "not " if $r != 7;
44+
print "ok 4 - no_proto $r\n";
45+
46+
47+
# ampersand with proto
48+
49+
$v = 3;
50+
$r = &with_proto + 4;
51+
print "not " if $v != 11;
52+
print "ok 5 - with_proto $v\n";
53+
print "not " if $r != 15;
54+
print "ok 6 - with_proto $r\n";
55+
56+
# ampersand without proto
57+
58+
$v = 3;
59+
$r = &no_proto + 4;
60+
print "not " if $v != 11;
61+
print "ok 7 - no_proto $v\n";
62+
print "not " if $r != 15;
63+
print "ok 8 - no_proto $r\n";
64+
65+
66+
# ampersand with proto, parenthesis
67+
68+
$v = 3;
69+
$r = &with_proto(4);
70+
print "not " if $v != 7;
71+
print "ok 9 - with_proto $v\n";
72+
print "not " if $r != 7;
73+
print "ok 10 - with_proto $r\n";
74+
75+
# ampersand without proto, with parenthesis
76+
77+
$v = 3;
78+
$r = &no_proto(4);
79+
print "not " if $v != 7;
80+
print "ok 11 - no_proto $v\n";
81+
print "not " if $r != 7;
82+
print "ok 12 - no_proto $r\n";
83+
84+
85+
# syntax with proto
86+
87+
$v = 3;
88+
$r = 0;
89+
eval ' $r = with_proto 4 ';
90+
$e = $@;
91+
print "not " if !$e;
92+
print "ok 13 - syntax error - '" . ( $e ? substr( $e, 0, 30 ) : '' ) . "...' \n";
93+
print "not " if $v != 3;
94+
print "ok 14 - with_proto $v\n";
95+
print "not " if $r != 0;
96+
print "ok 15 - with_proto $r\n";
97+
98+

0 commit comments

Comments
 (0)