Revision 27808

Date:
2009/07/30 03:37:31
Author:
kyle
Revision Log:
[t/spec] Tests for P5 style subs without signatures
Files:

Legend:

 
Added
 
Removed
 
Modified
  • t/spec/S06-signature/unspecified.t

     
    1 use v6;
    2 use Test;
    3
    4 plan 15;
    5
    6 sub simple { 'simple' }
    7 #?rakudo skip 'siglist'
    8 is &simple.signature, :(), 'signature is :() when none is specified';
    9 is simple(), 'simple', 'can call sub with no signature specified';
    10 is simple( :golf<hotel> ), 'simple',
    11 'can give named argument to sub with no signature';
    12 is simple( 'india' ), 'simple',
    13 'can give positional argument to sub with no signature';
    14
    15 sub positional { @_[0] }
    16 #?rakudo skip 'siglist'
    17 is &positional.signature, :(Any *@_),
    18 'signature is :(Any *@_) when none is specified and @_ is used';
    19 is positional( 'alpha' ), 'alpha', 'can call sub with positional param used';
    20 is positional(), undef, 'sub using positional param called with no params';
    21 is positional( :victor<whiskey> ), undef,
    22 'sub using positional param called with named param';
    23
    24 sub named { %_<bravo> }
    25 #?rakudo skip 'siglist'
    26 is &named.signature, :(Any *%_),
    27 'signature is :(Any *%_) when none is specified and %_ is used';
    28 is named( :bravo<charlie> ), 'charlie', 'can call sub with named param used';
    29 is named(), undef, 'named param sub is callable with no params';
    30 dies_ok { named( 'zulu' ) }, 'named param sub dies with positional param';
    31
    32 sub both { @_[1] ~ %_<delta> }
    33 #?rakudo skip 'siglist'
    34 is &both.signature, :(Any *@_, Any *%_),
    35 'signature is :(Any *@_, Any *%_) when none is specified and @_ and %_ are used';
    36 is both( 'x', :delta<echo>, 'foxtrot' ), 'foxtrotecho',
    37 'can call sub with both named and positional params used';
    38 is both(), undef ~ undef,
    39 'sub using both named and position params works with no params';