Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use typed exceptions for conditional operator
add test for RT #123115
  • Loading branch information
usev6 committed Mar 31, 2015
1 parent 7c4672c commit 82a4dd3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 6 additions & 2 deletions S03-operators/precedence.t
Expand Up @@ -111,8 +111,12 @@ is((1 && 0 ?? 2 !! 3), 3, "&& binds tighter than ??");
{
my $a = 0 ?? "yes" !! "no";
is($a, "no", "??!! binds tighter than =");
eval_dies_ok('$a ?? $a = 42 !! $a = 43', "Can't use assignop inside ??!!");
eval_dies_ok('$a ?? $a += 42 !! $a = 43', "Can't use meta-assignop inside ??!!");
throws_like { EVAL '$a ?? $a = 42 !! $a = 43' },
X::Syntax::ConditionalOperator::PrecedenceTooLoose,
"Can't use assignop inside ??!!";
throws_like { EVAL '$a ?? $a += 42 !! $a = 43' },
X::Syntax::ConditionalOperator::PrecedenceTooLoose,
"Can't use meta-assignop inside ??!!";
# (my $b = 1) ?? "true" !! "false";
# is($b, 1, "?? !! just thrown away with = in parens");
};
Expand Down
29 changes: 27 additions & 2 deletions S03-operators/ternary.t
Expand Up @@ -4,7 +4,7 @@ use Test;

#Ternary operator ?? !!

plan 17;
plan 21;
#L<S03/Changes to Perl 5 operators/"The ? : conditional operator becomes ?? !!">

my $str1 = "aaa";
Expand Down Expand Up @@ -63,10 +63,35 @@ is((4 or 5 ?? 6 !! 7), 4, "operator priority");
is($foo, "yay", "defining a postfix<!> doesn't screw up ternary op");
}

eval_dies_ok q[ 1 ?? 2,3 !! 4,5 ], 'Ternary error (RT 66840)';
# RT #66840
{
throws_like { EVAL '1 ?? 2,3 !! 4,5' },
X::Syntax::ConditionalOperator::PrecedenceTooLoose,
'Ternary error (RT 66840)';
}

eval_dies_ok q[ 71704 !! 'bust' ], 'Ternary error (RT 71704)';

throws_like { EVAL '1 ?? 3 :: 2' },
X::Syntax::ConditionalOperator::SecondPartInvalid,
'conditional operator written as ?? :: throws typed exception';

throws_like { EVAL '1 ?? b\n !! 2' },
X::Syntax::Confused,
'bogus code before !! of conditional operator is compile time error';

throws_like { EVAL '1 ?? 2' },
X::Syntax::Confused,
'missing !! of conditional operator is compile time error';

# RT #123115
{
sub rt123115 { 2 };
throws_like { EVAL '1 ?? foo !! 3' },
X::Syntax::ConditionalOperator::SecondPartGobbled,
'typed exception when listop gobbles the !! of conditional operator';
}

done;

# vim: ft=perl6

0 comments on commit 82a4dd3

Please sign in to comment.