Skip to content

Commit e0d65bb

Browse files
committed
fixup more unit tests inspired by remaining comments in PPC0024
1 parent e287ee0 commit e0d65bb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

t/class/method.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ no warnings 'experimental::class';
2626
# Turn off the 'signatures' feature to prove that 'method' is always
2727
# signatured even without it
2828
no feature 'signatures';
29+
no warnings 'experimental::signature_named_parameters';
2930

3031
class Testcase2 {
3132
method retfirst ( $x = 123 ) { return $x; }
33+
method retnamed ( :$named = 456 ) { return $named; }
3234
}
3335

3436
my $obj = Testcase2->new;
3537
is($obj->retfirst, 123, 'method signature params work');
3638
is($obj->retfirst(456), 456, 'method signature params skip $self');
3739

40+
is($obj->retnamed(named => 789), 789, 'method signature supports named parameters');
41+
3842
# argument counts take account of implicit $self
3943
my $e = eval { $obj->retfirst(1, 2) } ? undef : $@;
4044
like($e, qr/^Too many arguments for subroutine 'Testcase2::retfirst' \(got 3; expected at most 2\) /,

t/op/signatures.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ like $@, qr/^Missing required named parameter 'beta' to subroutine 'main::tnamed
933933
is eval("tnamed01(alpha => 1, beta => 2, gamma => 3)"), undef;
934934
like $@, qr/^Unrecognized named parameter 'gamma' to subroutine 'main::tnamed01' at /;
935935
is eval("tnamed01(alpha => 1, beta => 2, beta => 3, beta => 4)"), "alpha=1 beta=4";
936+
is eval("tnamed01(alpha => 'first', beta => 456, alpha => 'second')"), "alpha=second beta=456",
937+
"last value wins";
936938

937939
sub tnamed02 (:$alpha = "A", :$beta = "B") { "alpha=$alpha beta=$beta"; }
938940
is prototype(\&tnamed02), undef;

0 commit comments

Comments
 (0)