19 is($x // 0, 1, ' // : left-hand operand defined');
22 is($x // 1, 1, ' // : left-hand operand undef');
25 is($x // 0, '', ' // : left-hand operand defined but empty');
27 like([] // 0, qr/^ARRAY/, ' // : left-hand operand a referece');
30 is(($x err 0), 1, ' err: left-hand operand defined');
33 is(($x err 1), 1, ' err: left-hand operand undef');
36 is(($x err 0), '', ' err: left-hand operand defined but empty');
38 like(([] err 0), qr/^ARRAY/, ' err: left-hand operand a referece');
42 is($x, 1, ' //=: left-hand operand undefined');
45 is($x, 1, '//=: left-hand operand defined');
49 is($x, '', '//=: left-hand operand defined but empty');
51 @ARGV = (undef, 0, 3);
52 is(shift // 7, 7, 'shift // ... works');
53 is(shift() // 7, 0, 'shift() // ... works');
54 is(shift @ARGV // 7, 3, 'shift @array // ... works');
56 @ARGV = (3, 0, undef);
57 is(pop // 7, 7, 'pop // ... works');
58 is(pop() // 7, 0, 'pop() // ... works');
59 is(pop @ARGV // 7, 3, 'pop @array // ... works');
61 # Test that various syntaxes are allowed
63 for (qw(getc pos readline readlink undef umask <> <FOO> <$foo> -f)) {
64 eval "sub { $_ // 0 }";
65 is($@, '', "$_ // ... compiles");
68 # Test for some ambiguous syntaxes
70 eval q# sub f ($) { } f $x / 2; #;
72 eval q# sub f ($):lvalue { $y } f $x /= 2; #;
74 eval q# sub f ($) { } f $x /2; #;
75 like( $@, qr/^Search pattern not terminated/ );
76 eval q# sub { print $fh / 2 } #;
78 eval q# sub { print $fh /2 } #;
79 like( $@, qr/^Search pattern not terminated/ );
81 # [perl #28123] Perl optimizes // away incorrectly
83 is(0 // 2, 0, ' // : left-hand operand not optimized away');
84 is('' // 2, '', ' // : left-hand operand not optimized away');
85 is(undef // 2, 2, ' // : left-hand operand optimized away');