18 is($x // 0, 1, ' // : left-hand operand defined');
21 is($x // 1, 1, ' // : left-hand operand undef');
24 is($x // 0, '', ' // : left-hand operand defined but empty');
26 like([] // 0, qr/^ARRAY/, ' // : left-hand operand a referece');
29 is(($x err 0), 1, ' err: left-hand operand defined');
32 is(($x err 1), 1, ' err: left-hand operand undef');
35 is(($x err 0), '', ' err: left-hand operand defined but empty');
37 like(([] err 0), qr/^ARRAY/, ' err: left-hand operand a referece');
41 is($x, 1, ' //=: left-hand operand undefined');
44 is($x, 1, '//=: left-hand operand defined');
48 is($x, '', '//=: left-hand operand defined but empty');
50 @ARGV = (undef, 0, 3);
51 is(shift // 7, 7, 'shift // ... works');
52 is(shift() // 7, 0, 'shift() // ... works');
53 is(shift @ARGV // 7, 3, 'shift @array // ... works');
55 @ARGV = (3, 0, undef);
56 is(pop // 7, 7, 'pop // ... works');
57 is(pop() // 7, 0, 'pop() // ... works');
58 is(pop @ARGV // 7, 3, 'pop @array // ... works');
60 # Test that various syntaxes are allowed
62 for (qw(getc pos readline readlink undef umask <> <FOO> <$foo> -f)) {
63 eval "sub { $_ // 0 }";
64 is($@, '', "$_ // ... compiles");
67 # Test for some ambiguous syntaxes
69 eval q# sub f ($) { } f $x / 2; #;
71 eval q# sub f ($):lvalue { $y } f $x /= 2; #;
73 eval q# sub f ($) { } f $x /2; #;
74 like( $@, qr/^Search pattern not terminated/ );
75 eval q# sub { print $fh / 2 } #;
77 eval q# sub { print $fh /2 } #;
78 like( $@, qr/^Search pattern not terminated/ );
80 # [perl #28123] Perl optimizes // away incorrectly
82 is(0 // 2, 0, ' // : left-hand operand not optimized away');
83 is('' // 2, '', ' // : left-hand operand not optimized away');
84 is(undef // 2, 2, ' // : left-hand operand optimized away');