Skip to content

Commit 97a1050

Browse files
committed
Merge branch 'master' of github.com:perl6/roast
2 parents ded1b69 + 489c492 commit 97a1050

File tree

11 files changed

+184
-73
lines changed

11 files changed

+184
-73
lines changed

S02-names/pseudo.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6;
22

33
use Test;
44

5-
plan 142;
5+
plan 144;
66

77
# I'm not convinced this is in the right place
88
# Some parts of this testing (i.e. WHO) seem a bit more S10ish -sorear
@@ -412,4 +412,15 @@ my $x110 = 110; #OK
412412

413413
# PARENT - NYI in any compiler
414414

415+
# RT #123154
416+
{
417+
my $x = 'really unlikely value';
418+
ok MY::.values.grep({ ($_ // '') eq 'really unlikely value' }),
419+
'MY::.values actually produces values';
420+
{
421+
ok OUTER::.values.grep({ ($_ // '') eq 'really unlikely value' }),
422+
'OUTER::.values actually produces values';
423+
}
424+
}
425+
415426
# vim: ft=perl6

S02-types/bag.t

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 197;
4+
plan 199;
55

66
sub showkv($x) {
77
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
@@ -454,17 +454,6 @@ sub showkv($x) {
454454
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
455455
}
456456

457-
{
458-
my $b = <a b c>.Bag;
459-
#?rakudo.jvm todo "?"
460-
throws-like { $b.pairs[0].key++ },
461-
X::Parameter::RW,
462-
'Cannot change key of Bag.pairs';
463-
throws-like { $b.pairs[0].value++ },
464-
Exception, # no exception type yet
465-
'Cannot change value of Bag.pairs';
466-
}
467-
468457
#?rakudo todo 'we have not secured .WHICH creation yet RT #124454'
469458
{
470459
isnt 'a(1) Str|b(1) Str|c'.Bag.WHICH, <a b c>.Bag.WHICH,
@@ -492,4 +481,23 @@ sub showkv($x) {
492481
is showkv($b), 'a:5 b:1 foo:2', '...with the right elements';
493482
}
494483

484+
{
485+
my $b = <a>.Bag;
486+
throws-like { $b<a> = 42 },
487+
X::Assignment::RO,
488+
'Make sure we cannot assign on a key';
489+
490+
throws-like { $_ = 666 for $b.values },
491+
X::AdHoc, # X::Assignment::RO ???
492+
'Make sure we cannot assign on a .values alias';
493+
494+
throws-like { .value = 999 for $b.pairs },
495+
X::Assignment::RO,
496+
'Make sure we cannot assign on a .pairs alias';
497+
498+
throws-like { for $b.kv -> \k, \v { v = 22 } },
499+
X::Assignment::RO,
500+
'Make sure we cannot assign on a .kv alias';
501+
}
502+
495503
# vim: ft=perl6

S02-types/baghash.t

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 246;
4+
plan 254;
55

66
# L<S02/Mutable types/QuantHash of UInt>
77

@@ -532,3 +532,32 @@ sub showkv($x) {
532532
ok $b3.elems == 0,
533533
'named argument is happily eaten by .new method';
534534
}
535+
536+
{
537+
my $b = <a>.BagHash;
538+
$b<a> = 42;
539+
is $b<a>, 42, 'did we set an Int value';
540+
throws-like { $b<a> = "foo" },
541+
X::Multi::NoMatch, # X::TypeCheck::Assignment ???
542+
'Make sure we cannot assign Str on a key';
543+
544+
$_ = 666 for $b.values;
545+
is $b<a>, 666, 'did we set an Int value from a .values alias';
546+
throws-like { $_ = "foo" for $b.values },
547+
X::TypeCheck::Assignment,
548+
'Make sure we cannot assign Str on a .values alias';
549+
550+
.value = 999 for $b.pairs;
551+
is $b<a>, 999, 'did we set an Int value from a .pairs alias';
552+
throws-like { .value = "foo" for $b.pairs },
553+
X::TypeCheck::Assignment,
554+
'Make sure we cannot assign Str on a .pairs alias';
555+
556+
for $b.kv -> \k, \v { v = 22 };
557+
is $b<a>, 22, 'did we set an Int value from a .kv alias';
558+
throws-like { for $b.kv -> \k, \v { v = "foo" } },
559+
X::TypeCheck::Assignment,
560+
'Make sure we cannot assign Str on a .kv alias';
561+
}
562+
563+
# vim: ft=perl6

S02-types/mix.t

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 178;
4+
plan 180;
55

66
sub showkv($x) {
77
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
@@ -410,21 +410,29 @@ sub showkv($x) {
410410
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
411411
}
412412

413-
{
414-
my $m = <a b c>.Mix;
415-
#?rakudo.jvm todo "?"
416-
throws-like { $m.pairs[0].key++ },
417-
X::Parameter::RW,
418-
'Cannot change key of Mix.pairs';
419-
throws-like { $m.pairs[0].value++ },
420-
Exception,
421-
'Cannot change value of Mix.pairs';
422-
}
423-
424413
#?rakudo todo 'we have not secured .WHICH creation yet RT #124496'
425414
{
426415
isnt 'a(1) Str|b(1) Str|c'.Mix.WHICH, <a b c>.Mix.WHICH,
427416
'Faulty .WHICH creation';
428417
}
429418

419+
{
420+
my $m = <a>.Mix;
421+
throws-like { $m<a> = 42.1 },
422+
X::Assignment::RO,
423+
'Make sure we cannot assign on a key';
424+
425+
throws-like { $_ = 666.1 for $m.values },
426+
X::AdHoc, # X::Assignment::RO ???
427+
'Make sure we cannot assign on a .values alias';
428+
429+
throws-like { .value = 999.1 for $m.pairs },
430+
X::Assignment::RO,
431+
'Make sure we cannot assign on a .pairs alias';
432+
433+
throws-like { for $m.kv -> \k, \v { v = 22.1 } },
434+
X::Assignment::RO,
435+
'Make sure we cannot assign on a .kv alias';
436+
}
437+
430438
# vim: ft=perl6

S02-types/mixhash.t

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 209;
4+
plan 217;
55

66
# L<S02/Mutable types/QuantHash of UInt>
77

@@ -450,4 +450,31 @@ sub showkv($x) {
450450
is $e.fmt('%s,%s',':'), "", '.fmt(%s%s,sep) works (empty)';
451451
}
452452

453+
{
454+
my $m = <a>.MixHash;
455+
$m<a> = 42.1;
456+
is $m<a>, 42.1, 'did we set a Real value';
457+
throws-like { $m<a> = "foo" },
458+
X::Str::Numeric, # X::TypeCheck::Assignment ???
459+
'Make sure we cannot assign Str on a key';
460+
461+
$_ = 666.1 for $m.values;
462+
is $m<a>, 666.1, 'did we set a Real value from a .values alias';
463+
throws-like { $_ = "foo" for $m.values },
464+
X::TypeCheck::Assignment,
465+
'Make sure we cannot assign Str on a .values alias';
466+
467+
.value = 999.1 for $m.pairs;
468+
is $m<a>, 999.1, 'did we set a Real value from a .pairs alias';
469+
throws-like { .value = "foo" for $m.pairs },
470+
X::TypeCheck::Assignment,
471+
'Make sure we cannot assign Str on a .pairs alias';
472+
473+
for $m.kv -> \k, \v { v = 22.1 };
474+
is $m<a>, 22.1, 'did we set a Real value from a .kv alias';
475+
throws-like { for $m.kv -> \k, \v { v = "foo" } },
476+
X::TypeCheck::Assignment,
477+
'Make sure we cannot assign Str on a .kv alias';
478+
}
479+
453480
# vim: ft=perl6

S02-types/pair.t

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use v6;
22

33
use Test;
44

5-
plan 3 * 19 + 94;
5+
plan 4 * 19 + 100;
66

77
# L<S02/Mutable types/A single key-to-value association>
88
# basic Pair
99

1010
for
1111
foo => "bar", 'fat-comma',
12-
Pair.new(:key<foo>, :value<bar>), 'Pair.new',
12+
Pair.new(:key<foo>, :value<bar>), 'Pair.new(:key,:value)',
13+
Pair.new("foo", "bar"), 'Pair.new(key,value)',
1314
pair("foo","bar"), 'pair()'
1415
-> $pair, $type {
1516
diag "checking $type";
@@ -360,4 +361,20 @@ Note, "non-chaining binary" was later renamed to "structural infix".
360361
is ((1|2|3) => 1&2&3).gist, 'any(1, 2, 3) => all(1, 2, 3)', "both key and value can convey a Junction object";
361362
}
362363

364+
{
365+
my $p = Pair.new("foo",my Int $);
366+
isa-ok $p.value, Int;
367+
is ($p.value = 42), 42, 'can assign integer value and return that';
368+
is $p.value, 42, 'the expected Int value was set';
369+
throws-like { $p.value = "bar" },
370+
X::TypeCheck::Assignment,
371+
'cannot assign a Str to an Int';
372+
373+
$p.freeze;
374+
throws-like { $p.value = 666 },
375+
X::Assignment::RO,
376+
'cannot assign an Int to a frozen';
377+
is $p.value, 42, 'did not change integer value';
378+
}
379+
363380
# vim: ft=perl6

S04-phasers/enter-leave.t

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test;
55
use lib 't/spec/packages';
66
use Test::Util;
77

8-
plan 28;
8+
plan 30;
99

1010
# L<S04/Phasers/ENTER "at every block entry time">
1111
# L<S04/Phasers/LEAVE "at every block exit time">
@@ -182,14 +182,14 @@ plan 28;
182182
# RT #121530
183183
#?niecza todo '@!'
184184
#?rakudo.jvm todo 'unwind, RT #121530'
185-
#?rakudo.moar todo 'unwind, RT #121530'
186185
{
187186
my $str;
188187
try {
189188
LEAVE { $str ~= '1' }
190189
LEAVE { $str ~= '2'; die 'foo' }
191190
}
192191
is $str, '21', 'die doesn\'t abort LEAVE queue';
192+
is $!.message, 'foo', 'single exception from LEAVE is rethrown after running LEAVEs';
193193
}
194194

195195
# RT #113548
@@ -265,4 +265,13 @@ plan 28;
265265
is doit(), 'ls', 'return in nested block with LEAVE works';
266266
}
267267

268+
{
269+
sub foo() {
270+
LEAVE die 'wtf';
271+
LEAVE die 'omg';
272+
}
273+
throws-like { foo() }, X::PhaserExceptions,
274+
exceptions => sub (@ex) { @ex>>.message ~~ <omg wtf> };
275+
}
276+
268277
# vim: ft=perl6

S12-methods/fallback.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ is F.new.something(''), 'Str', 'Can multi-dispatch on regular arguments (also on
5656
dies-ok { F.something() }, 'Error when none of the candidates match';
5757

5858
class I {
59-
method postcircumfix:<( )>(|) { 'invaught' }
59+
method CALL-ME { 'invaught' }
6060
method FALLBACK($name, |c) { 'yes, I work' }
6161
}
6262
my $i = I.new;
63-
is $i.spy, 'yes, I work', 'FALLBACK is effective with a postcircumfix:<( )>';
64-
is $i(), 'invaught', 'postcircumfix:<( )> beats FALLBACK';
63+
is $i.spy, 'yes, I work', 'FALLBACK is effective with a CALL-ME';
64+
is $i(), 'invaught', 'CALL-ME beats FALLBACK';
6565

6666
# vim: ft=perl6

S13-overloading/operators.t

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 5;
4+
plan 6;
55

66
#L<S06/Operator overloading>
77

@@ -23,14 +23,16 @@ plan 5;
2323
}
2424

2525
{
26+
my @keys;
2627
class A does Associative {
27-
method postcircumfix:<{ }>(*@ix) { # METHOD TO SUB CASUALTY
28-
return @ix
28+
multi method AT-KEY(A:D: $key) {
29+
push @keys, $key;
30+
++state $i
2931
}
3032
};
3133

32-
#?rakudo skip 'cannot easily override {} at the moment'
33-
is A.new<foo bar>, <foo bar>, 'defining postcircumfix:<{ }> works';
34+
is A.new<foo bar>, (1, 2), 'implementing AT-KEY gets {...} indexing working';
35+
is @keys, [<foo bar>], 'AT-KEY called once for each key';
3436
}
3537

3638
# overloaded invoke
@@ -41,7 +43,7 @@ plan 5;
4143
{
4244
class B {
4345
has $.x;
44-
method postcircumfix:<( )>($y) {
46+
method CALL-ME($y) {
4547
$.x ~ $y;
4648
}
4749
}

0 commit comments

Comments
 (0)