Commit | Line | Data |
c963b151 |
1 | #!./perl |
2 | |
3 | # Test // and friends. |
4 | |
5 | BEGIN { |
6 | chdir 't' if -d 't'; |
7 | @INC = '../lib'; |
8 | } |
9 | |
10 | package main; |
11 | require './test.pl'; |
12 | |
6f33ba73 |
13 | plan( tests => 25 ); |
c963b151 |
14 | |
15 | my($x); |
16 | |
17 | $x=1; |
18 | is($x // 0, 1, ' // : left-hand operand defined'); |
19 | |
20 | $x = undef; |
21 | is($x // 1, 1, ' // : left-hand operand undef'); |
22 | |
23 | $x=''; |
24 | is($x // 0, '', ' // : left-hand operand defined but empty'); |
25 | |
26 | $x=1; |
27 | is(($x err 0), 1, ' err: left-hand operand defined'); |
28 | |
29 | $x = undef; |
30 | is(($x err 1), 1, ' err: left-hand operand undef'); |
31 | |
32 | $x=''; |
33 | is(($x err 0), '', ' err: left-hand operand defined but empty'); |
34 | |
35 | $x=undef; |
36 | $x //= 1; |
37 | is($x, 1, ' //=: left-hand operand undefined'); |
38 | |
39 | $x //= 0; |
40 | is($x, 1, ' //=: left-hand operand defined'); |
41 | |
42 | $x = ''; |
43 | $x //= 0; |
44 | is($x, '', ' //=: left-hand operand defined but empty'); |
6f33ba73 |
45 | |
46 | @ARGV = (undef, 0, 3); |
47 | is(shift // 7, 7, 'shift // ... works'); |
48 | is(shift() // 7, 0, 'shift() // ... works'); |
49 | is(shift @ARGV // 7, 3, 'shift @array // ... works'); |
50 | |
51 | @ARGV = (3, 0, undef); |
52 | is(pop // 7, 7, 'pop // ... works'); |
53 | is(pop() // 7, 0, 'pop() // ... works'); |
54 | is(pop @ARGV // 7, 3, 'pop @array // ... works'); |
55 | |
56 | # Test that various syntaxes are allowed |
57 | |
58 | for (qw(getc pos readline readlink undef umask <> <FOO> <$foo> -f)) { |
59 | eval "sub { $_ // 0 }"; |
60 | is($@, '', "$_ // ... compiles"); |
61 | } |