Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
basic tests for sigilless params
  • Loading branch information
moritz committed Aug 19, 2012
1 parent 73f0563 commit 12f1b31
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
46 changes: 46 additions & 0 deletions S06-signature/sigilless.t
@@ -0,0 +1,46 @@
use v6;
use Test;

plan 10;

# test \term
{
sub identity(\x) { x }

sub count(\x) {
my $c = 0;
++$c for x;
$c
}

sub swap(\x, \y) {
my $z = y;
y = x;
x = $z;
}

is identity('foo'), 'foo',
'basic passing of an argument to backslashed identifier';
is count((1, 2, 3)), 3, 'passing of flattening arguments ';
is count([1, 2, 3]), 1, 'passing of non-flatteing arguments';

my $a = 5;
my $b = 3;
lives_ok { eval 'swap($a, $b)' }, 'backslash does not make read-only';
is "$a|$b", '3|5', 'swapping worked';
dies_ok { eval 'swap(42, $a)' }, 'no additional writable containers involved';
}

# test |term
{
sub pass-on(&c, |args) { c(|args) }
sub join-em(|args) { args.list.join('|') }

is pass-on(-> $a, $b { $a + $b }, 2, 3), 5, '|args sanity (1)';
is join-em('foo', 42), 'foo|42', '|args sanity (2)';
is join-em(pass-on(-> $a, $b { $a + $b }, 2, 3), 42),
'5|42', 'combined sanity';

is pass-on({ $:l~ $:w }, :w<6>, :l<p>), 'p6', 'named arguments';

}
13 changes: 7 additions & 6 deletions S32-exceptions/misc.t
Expand Up @@ -9,7 +9,8 @@ throws_like 'pack("B", 1)', X::Buf::Pack, directive => 'B';
throws_like 'Buf.new.unpack("B")', X::Buf::Pack, directive => 'B';
throws_like 'pack "A1", "mÄ"', X::Buf::Pack::NonASCII, char => 'Ä';
throws_like 'my class Foo { method a() { $!bar } }', X::Attribute::Undeclared,
name => '$!bar', package-name => 'Foo';
symbol => '$!bar', package-name => 'Foo', package-kind => 'class',
what => 'attribute';
throws_like 'sub f() { $^x }', X::Signature::Placeholder,
line => 1;

Expand All @@ -27,8 +28,8 @@ throws_like '@_', X::Placeholder::Mainline, placeholder => '@_';
throws_like '"foo".{ say $^a }', X::Placeholder::Mainline;


throws_like 'sub f(*@a = 2) { }', X::Parameter::Default, how => 'slurpy';
throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required';
throws_like 'sub f(*@ = 2) { }', X::Parameter::Default, how => 'slurpy', parameter => *.not;
throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required', parameter => '$x';
throws_like 'sub f(:$x! = 3) { }', X::Parameter::Default, how => 'required';
throws_like 'sub f($:x) { }', X::Parameter::Placeholder,
parameter => '$:x',
Expand Down Expand Up @@ -138,17 +139,17 @@ throws_like '$.a', X::Syntax::NoSelf, variable => '$.a';
throws_like 'my class B0Rk { $.a }', X::Syntax::NoSelf, variable => '$.a';

throws_like 'has $.x', X::Attribute::NoPackage;
throws_like 'my module A { has $.x }', X::Attribute::Package, package-type => 'module';
throws_like 'my module A { has $.x }', X::Attribute::Package, package-kind => 'module';

throws_like 'has sub a() { }', X::Declaration::Scope, scope => 'has', declaration => 'sub';
throws_like 'has package a { }', X::Declaration::Scope, scope => 'has', declaration => 'package';
throws_like 'our multi a() { }', X::Declaration::Scope::Multi, scope => 'our';
throws_like 'multi sub () { }', X::Anon::Multi, multiness => 'multi';
throws_like 'proto sub () { }', X::Anon::Multi, multiness => 'proto';
throws_like 'class { multi method () { }}', X::Anon::Multi, routine-type => 'method';
throws_like 'use MONKEY_TYPING; augment class { }', X::Anon::Augment, package-type => 'class';
throws_like 'use MONKEY_TYPING; augment class { }', X::Anon::Augment, package-kind => 'class';
throws_like 'use MONKEY_TYPING; augment class NoSuchClass { }', X::Augment::NoSuchType,
package-type => 'class',
package-kind => 'class',
package => 'NoSuchClass';
throws_like 'use MONKEY_TYPING; augment class No::Such::Class { }', X::Augment::NoSuchType,
package => 'No::Such::Class';
Expand Down

0 comments on commit 12f1b31

Please sign in to comment.