This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
some WinCE compilers require a little correction
[perl5.git] / t / op / dor.t
CommitLineData
c963b151
BD
1#!./perl
2
3# Test // and friends.
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8}
9
10package main;
11require './test.pl';
12
7ce6e6b9 13plan( tests => 30 );
c963b151
BD
14
15my($x);
16
17$x=1;
18is($x // 0, 1, ' // : left-hand operand defined');
19
20$x = undef;
21is($x // 1, 1, ' // : left-hand operand undef');
22
23$x='';
24is($x // 0, '', ' // : left-hand operand defined but empty');
25
26$x=1;
27is(($x err 0), 1, ' err: left-hand operand defined');
28
29$x = undef;
30is(($x err 1), 1, ' err: left-hand operand undef');
31
32$x='';
33is(($x err 0), '', ' err: left-hand operand defined but empty');
34
35$x=undef;
36$x //= 1;
37is($x, 1, ' //=: left-hand operand undefined');
38
39$x //= 0;
40is($x, 1, ' //=: left-hand operand defined');
41
42$x = '';
43$x //= 0;
44is($x, '', ' //=: left-hand operand defined but empty');
6f33ba73
RGS
45
46@ARGV = (undef, 0, 3);
47is(shift // 7, 7, 'shift // ... works');
48is(shift() // 7, 0, 'shift() // ... works');
49is(shift @ARGV // 7, 3, 'shift @array // ... works');
50
51@ARGV = (3, 0, undef);
52is(pop // 7, 7, 'pop // ... works');
53is(pop() // 7, 0, 'pop() // ... works');
54is(pop @ARGV // 7, 3, 'pop @array // ... works');
55
56# Test that various syntaxes are allowed
57
58for (qw(getc pos readline readlink undef umask <> <FOO> <$foo> -f)) {
59 eval "sub { $_ // 0 }";
60 is($@, '', "$_ // ... compiles");
61}
7ce6e6b9
RGS
62
63# Test for some ambiguous syntaxes
64
65eval q# sub f ($) { } f $x / 2; #;
66is( $@, '' );
67eval q# sub f ($):lvalue { $y } f $x /= 2; #;
68is( $@, '' );
69eval q# sub f ($) { } f $x /2; #;
70like( $@, qr/^Search pattern not terminated/ );
71eval q# sub { print $fh / 2 } #;
72is( $@, '' );
73eval q# sub { print $fh /2 } #;
74like( $@, qr/^Search pattern not terminated/ );