# New Ticket Created by Zev Benjamin # Please include the string: [perl #49354] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=49354 >
Attached are some tests from the NQP TODO file. I attempted to make reasonable guesses about where NQP diverges from perl6, but erred on the side of additional functionality. Zev
Index: t/23-named_args.t =================================================================== --- t/23-named_args.t (revision 0) +++ t/23-named_args.t (revision 0) @@ -0,0 +1,32 @@ +#!./parrot + +# test named arguments + +plan(7); + +sub f1 ($x, :$y) { $x - $y; } + +say('ok ', f1(2, :y(1)), ' # named args passable'); + +sub f2 ($x, :$y) { $x; } + +say('ok ', f2(2), ' # named args ignorable'); + +sub f3 (:$x, :$y) { $x - $y; } + +say('ok ', f3(:y(2), :x(5)), ' # args reorderable'); + +sub f4 ($w, $x, :$y, :$z) { $w + $x + $y + $z; } + +say('ok ', f4(:z(2), -3, :y(1), 4), ' # named/positional intermixable'); + +sub f5 ($x, :short($longname)) { $x - $longname; } + +say('ok ', f5(10, :short(5)), ' # short vs. long names'); + +sub f6 ($x, :s(:short($longname))) { $x - $longname; } + +say('ok ', f6(10, :short(4)), ' # multiple short names'); +say('ok ', f6(10, :s(3)), ' # multiple short names'); + +# XXX: test mandatory named args are actually mandatory Property changes on: t/23-named_args.t ___________________________________________________________________ Name: svn:mime-type + text/plain Index: t/22-optional_args.t =================================================================== --- t/22-optional_args.t (revision 0) +++ t/22-optional_args.t (revision 0) @@ -0,0 +1,31 @@ +#!./parrot + +# test optional arguments and parameters + +plan(6); + +sub f1 ($x, $y!, $z?) { + $x; +} + +say('ok ', f1(1, 2), ' # optional args ignorable'); +say('ok ', f1(2, 2, 2), ' # optional args passable'); + +sub f2 ($x?, $y?) { 'ok 3 # only optional args'; } + +say(f2()); + +sub f3 ($x, $y?, $text?) { + if ! $y.defined() && ! $text.defined() { + say('ok 4 # unpassed optional args are undef'); + } else { + say('ok ', $x - $y, $text); + } +} + +f3(2); +f3(8, 3, ' # optional args get passed values'); +f3(8, :text(' # optional args specifiable by name'), :y(2)); + +# XXX: need to be able to test that the following is illegal +#sub f4 ($x?, $y) { $y; } Property changes on: t/22-optional_args.t ___________________________________________________________________ Name: svn:mime-type + text/plain Index: t/21-scalar_context.t =================================================================== --- t/21-scalar_context.t (revision 0) +++ t/21-scalar_context.t (revision 0) @@ -0,0 +1,22 @@ +#!./parrot + +# test scalar context operator + +plan(6); + +say('ok ', $(1), ' # nop on numeric constant'); +say('ok ', $('2'), '# nop on string constant'); +say('ok ', $(1 + 2), '# constant expression'); + +my $x := 4; +say('ok ', $($x), '# numeric variable'); + +my $y := 'ok 5'; +say($($y), '# string variable'); + +my $array := $(1, 2, 3); + +if ! $array.isa('Array') { + print('not '); +} +say('ok 6 # list promotion to Array'); Property changes on: t/21-scalar_context.t ___________________________________________________________________ Name: svn:mime-type + text/plain Index: t/19-hash_access.t =================================================================== --- t/19-hash_access.t (revision 0) +++ t/19-hash_access.t (revision 0) @@ -0,0 +1,26 @@ +#!./parrot + +# check hash access methods + +plan(7); + +my %h; + +%h<a> := 1; +say("ok 1 # hash assignment with numeric value doesn't barf"); + +say('ok ', %h<a> + 1, ' # hash access to numeric value'); + +%h<a> := 'ok 3'; +say(%h<a>, ' # hash access to string value'); + +%h{1} := '4'; +say('ok ', %h{1}, ' # numeric hash access'); + +say('ok ', %h<1> + 1, ' # numbers stringify'); + +%h{'b'} := 'ok 6 # single quoted curly braces work'; +say(%h{'b'}); + +%h{"foo"} := "ok 7 # double quoted curly braces work"; +say(%h{"foo"}); Property changes on: t/19-hash_access.t ___________________________________________________________________ Name: svn:mime-type + text/plain Index: t/20-list_access.t =================================================================== --- t/20-list_access.t (revision 0) +++ t/20-list_access.t (revision 0) @@ -0,0 +1,25 @@ +#!./parrot + +# check list access methods + +plan(7); + +my @l := 1,2,3,4,5; + +say("ok 1 # list assignment didn't barf"); +say('ok ', @l[1], ' # numeric subscript'); +say('ok ', @l['2'], ' # string subscript'); + +my $idx := 3; + +say('ok ', @l[$idx], ' # variable subscript'); +say('ok ', @l[$idx + 1], '# expression in subscript'); + [EMAIL PROTECTED] := 'ok 5 # string array element'; +say(@l[0]); + [EMAIL PROTECTED] := 'ok 6 # automatic expansion'; +say(@l[10]); + [EMAIL PROTECTED] := 'ok 7 # negative subscripts'; +say(@l[10]); Property changes on: t/20-list_access.t ___________________________________________________________________ Name: svn:mime-type + text/plain Index: TODO.pod =================================================================== --- TODO.pod (revision 24517) +++ TODO.pod (working copy) @@ -41,20 +41,16 @@ We should be able to load an external module (Pm suggests Test.pbc) and exercise methods using that. -=item * Hash key access C<$varE<lt>someKeyE<gt>> - -=item * List member access C<$var[index]> - =item * Match variable access C<$/> -=item * Scalar context $( ... ) +=item * More tests for scalar context $( ... ) =item * List context @( ... ) =item * Variables with twigils -=item * Optional arguments and parameters +=item * More tests for optional arguments and parameters -=item * Named arguments and parameters +=item * More tests for Named arguments and parameters =back