Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

basic tests for sigilless params

  • Loading branch information...
commit 12f1b31878b6dd1702a3c7e2afbdb79f2adfffb1 1 parent 73f0563
@moritz moritz authored
Showing with 53 additions and 6 deletions.
  1. +46 −0 S06-signature/sigilless.t
  2. +7 −6 S32-exceptions/misc.t
View
46 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';
+
+}
View
13 S32-exceptions/misc.t
@@ -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;
@@ -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',
@@ -138,7 +139,7 @@ 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';
@@ -146,9 +147,9 @@ 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';
Please sign in to comment.
Something went wrong with that request. Please try again.