Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Last batch of dies_ok -> throws_like cleanup
  • Loading branch information
lizmat committed Aug 19, 2014
1 parent 2c0ae6c commit 8120b6b
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 37 deletions.
3 changes: 2 additions & 1 deletion S02-lexical-conventions/comments.t
Expand Up @@ -157,7 +157,8 @@ plan 51;
# L<S02/Comments in Unspaces and vice versa/"comment may not contain an unspace">
#?niecza skip 'Excess arguments to CORE eval'
{
dies_ok { EVAL '$a = #`\ (comment) 32' },
throws_like { EVAL '$a = #`\ (comment) 32' },
X::Undeclared,
"comments can't contain unspace";
}

Expand Down
3 changes: 2 additions & 1 deletion S02-lexical-conventions/unicode.t
Expand Up @@ -133,7 +133,8 @@ lives_ok { EVAL "q\x298d test \x298e" },
"Unicode open-298d maps to close-298e";
lives_ok { EVAL "q\x301d test \x301e" },
"Unicode open-301d maps to close-301e";
dies_ok { EVAL "q\x301d test \x301f" },
throws_like { EVAL "q\x301d test \x301f" },
X::AdHoc,
"Unicode open-301d does not map to close-301f";
lives_ok { EVAL "q\x2018 test \x2019" },
"Unicode open-2018 maps to to close-2019";
Expand Down
2 changes: 1 addition & 1 deletion S02-types/int-uint.t
Expand Up @@ -6,7 +6,7 @@ use Test;
my @inttypes = <1 2 4 8 16 32 64>.map({
"int$_","uint$_"
}).grep: {
try EVAL "my $_ \$var; \$var.WHAT eq \"($_)\""
try EVAL "my $_ \$var; \$var.WHAT eq '($_)'"
};

# nothing to test, we're done
Expand Down
19 changes: 11 additions & 8 deletions S02-types/lists.t
Expand Up @@ -26,8 +26,9 @@ plan 28;

is ($foo, "does_not_matter")[*-2], 42,
"indexing lists by a negative index works correctly";
eval_dies_ok(q/my @a = <one two>; @a[-1] = 'zero'; @a.perl/,
"indexing lists by a negative index without the * dies");
throws_like { EVAL q/my @a = <one two>; @a[-1] = 'zero'; @a.perl/ },
X::Subscript::FromEnd,
"indexing lists by a negative index without the * dies";
}

# List construction does not create new containers
Expand Down Expand Up @@ -72,7 +73,8 @@ plan 28;
ok $foo == 23 && $bar == 24,
"using list slices as lvalues works (1)";

dies_ok { ($foo, 42, $bar, 19)[1, 3] = (23, 24) },
throws_like { ($foo, 42, $bar, 19)[1, 3] = (23, 24) },
X::Assignment::RO,
"using list slices as lvalues works (2)";
}

Expand Down Expand Up @@ -136,8 +138,9 @@ plan 28;
{
sub Parcel::rt62836 { 62836 }

dies_ok { <1 2 3>.rt62836 },
'call to user-declared sub in Parcel:: class dies';
throws_like { <1 2 3>.rt62836 },
X::Method::NotFound,
'call to user-declared sub in Parcel:: class dies';
try { EVAL '<1 2 3>.rt62836' };
ok "$!" ~~ /rt62836/, 'error message contains name of sub';
ok "$!" ~~ /Parcel/, 'error message contains name of class';
Expand All @@ -152,7 +155,9 @@ plan 28;
isa_ok $rt66304, Parcel, 'List assigned to scalar is-a Parcel';
is( $rt66304.WHAT, (1, 2, 4).WHAT,
'List.WHAT is the same as .WHAT of list assigned to scalar' );
dies_ok { $rt66304[1] = 'ro' }, 'literal List element is immutable';
throws_like { $rt66304[1] = 'ro' },
X::Assignment::RO,
'literal List element is immutable';
is $rt66304, (1, 2, 4), 'List is not changed by attempted assignment';
}

Expand All @@ -169,6 +174,4 @@ plan 28;
#?niecza skip 'loops'
is 'foo'[2..*].elems, 0, 'can range-index a Str with infinite range';

done;

# vim: ft=perl6
68 changes: 51 additions & 17 deletions S02-types/mix.t
Expand Up @@ -32,12 +32,24 @@ sub showkv($x) {
isa_ok $hash, Hash, "...and it returned a Hash";
is showkv($hash), 'a:5 b:1 foo:2', '...with the right elements';

dies_ok { $m<a> = 5 }, "Can't assign to an element (Mixs are immutable)";
dies_ok { $m<a>++ }, "Can't increment an element (Mixs are immutable)";
dies_ok { $m.keys = <c d> }, "Can't assign to .keys";
dies_ok { $m.values = 3, 4 }, "Can't assign to .values";
dies_ok { $m<a>:delete }, "Can't :delete from Mix";
dies_ok { $m.delete_key("a") }, "Can't .delete_key from Mix";
throws_like { $m<a> = 5 },
X::Assignment::RO,
"Can't assign to an element (Mixs are immutable)";
throws_like { $m<a>++ },
X::AdHoc,
"Can't increment an element (Mixs are immutable)";
throws_like { $m.keys = <c d> },
X::Assignment::RO,
"Can't assign to .keys";
throws_like { $m.values = 3, 4 },
X::Assignment::RO,
"Can't assign to .values";
throws_like { $m<a>:delete },
X::Immutable,
"Can't :delete from Mix";
throws_like { $m.delete_key("a") },
X::Immutable,
"Can't .delete_key from Mix";

is ~$m<a b>, "5 1", 'Multiple-element access';
is ~$m<a santa b easterbunny>, "5 0 1 0", 'Multiple-element access (with nonexistent elements)';
Expand Down Expand Up @@ -83,8 +95,12 @@ sub showkv($x) {
my $m = mix <a a b foo>;
is $m<a>:exists, True, ':exists with existing element';
is $m<santa>:exists, False, ':exists with nonexistent element';
dies_ok { $m<a>:delete }, ':delete does not work on mix';
dies_ok { $m.delete_key("a") }, '.delete_key does not work on mix';
throws_like { $m<a>:delete },
X::Immutable,
':delete does not work on mix';
throws_like { $m.delete_key("a") },
X::Immutable,
'.delete_key does not work on mix';
}

{
Expand Down Expand Up @@ -170,10 +186,18 @@ sub showkv($x) {
is %m<b>, 2, 'Single-key subscript (existing element)';
is %m<santa>, 0, 'Single-key subscript (nonexistent element)';

dies_ok { %m<a> = 1 }, "Can't assign to an element (Mixs are immutable)";
dies_ok { %m = mix <a b> }, "Can't assign to a %var implemented by Mix";
dies_ok { %m<a>:delete }, "Can't :delete from a Mix";
dies_ok { %m.delete_key("a") }, "Can't .delete_key from a Mix";
throws_like { %m<a> = 1 },
X::Assignment::RO,
"Can't assign to an element (Mixs are immutable)";
throws_like { %m = mix <a b> },
X::Assignment::RO,
"Can't assign to a %var implemented by Mix";
throws_like { %m<a>:delete },
X::Immutable,
"Can't :delete from a Mix";
throws_like { %m.delete_key("a") },
X::Immutable,
"Can't .delete_key from a Mix";
}

{
Expand Down Expand Up @@ -285,23 +309,29 @@ sub showkv($x) {

{
my $m = Mix.new("a", "b", "b");
dies_ok { $m.pick }, '.pick does not work on Mix';
throws_like { $m.pick },
X::AdHoc,
'.pick does not work on Mix';
}

# L<S32::Containers/Mix/grab>

#?niecza skip '.grab NYI'
{
my $m = mix <a b b c c c>;
dies_ok { $m.grab }, 'cannot call .grab on a Mix';
throws_like { $m.grab },
X::Immutable,
'cannot call .grab on a Mix';
}

# L<S32::Containers/Mix/grabpairs>

#?niecza skip '.grabpairs NYI'
{
my $m = mix <a b b c c c>;
dies_ok { $m.grabpairs }, 'cannot call .grabpairs on a Mix';
throws_like { $m.grabpairs },
X::Immutable,
'cannot call .grabpairs on a Mix';
}

{
Expand Down Expand Up @@ -382,8 +412,12 @@ sub showkv($x) {

{
my $m = <a b c>.Mix;
dies_ok { $m.pairs[0].key++ }, 'Cannot change key of Mix.pairs';
dies_ok { $m.pairs[0].value++ }, 'Cannot change value of Mix.pairs';
throws_like { $m.pairs[0].key++ },
X::Assignment::RO,
'Cannot change key of Mix.pairs';
throws_like { $m.pairs[0].value++ },
X::AdHoc,
'Cannot change value of Mix.pairs';
}

# vim: ft=perl6
16 changes: 12 additions & 4 deletions S02-types/mixhash.t
Expand Up @@ -37,8 +37,12 @@ sub showkv($x) {
isa_ok $hash, Hash, "...and it returned a Hash";
is showkv($hash), 'a:5 b:1 foo:2', '...with the right elements';

dies_ok { $m.keys = <c d> }, "Can't assign to .keys";
dies_ok { $m.values = 3, 4 }, "Can't assign to .values";
throws_like { $m.keys = <c d> },
X::Assignment::RO,
"Can't assign to .keys";
throws_like { $m.values = 3, 4 },
X::Assignment::RO,
"Can't assign to .values";

is ~$m<a b>, "5 1", 'Multiple-element access';
is ~$m<a santa b easterbunny>, "5 0 1 0", 'Multiple-element access (with nonexistent elements)';
Expand Down Expand Up @@ -302,15 +306,19 @@ sub showkv($x) {

{
my $m = MixHash.new("a", "b", "b");
dies_ok { $m.pick }, '.pick does not work on MixHash';
throws_like { $m.pick },
X::AdHoc,
'.pick does not work on MixHash';
}

# L<S32::Containers/MixHash/grab>

#?niecza skip '.grab NYI'
{
my $m = <a b b c c c>.MixHash;
dies_ok { $m.grab }, 'cannot call .grab on a MixHash';
throws_like { $m.grab },
X::AdHoc,
'cannot call .grab on a MixHash';
}


Expand Down
8 changes: 6 additions & 2 deletions S02-types/multi_dimensional_array.t
Expand Up @@ -24,7 +24,9 @@ plan 58;
is(@md[0;1], 2, 'accessing an array as [0;0] works (2)');
is(@md[1;0], 4, 'accessing an array as [0;0] works (3)');
is(@md[1;1], 6, 'accessing an array as [0;0] works (4)');
dies_ok({@md[1;2] = 5}, 'setting a multi-d array beyond boundaries fails');
throws_like {@md[1;2] = 5},
X::AdHoc, # XXX fix when we have multi-dimensional arrays
'setting a multi-d array beyond boundaries fails';

is(@md.elems, 4, '.elems works on multidimensional array');
}
Expand All @@ -36,7 +38,9 @@ plan 58;
@md[9;9;1] = 'bar';
is(@md[0;0;0], 'foo', 'accessing a partially bounded array works (1)');
is(@md[9;9;1], 'bar', 'accessing a partially bounded array works (2)');
dies_ok({@md[0;0;2] = 9}, 'setting a partially bounded multi-d array beyond boundaries fails');
throws_like {@md[0;0;2] = 9},
X::AdHoc, # XXX fix when we have multi-dimensional arrays
'setting a partially bounded multi-d array beyond boundaries fails';

is(@md.elems, 2, '.elems works on partially bounded multi-d array');
}
Expand Down
4 changes: 3 additions & 1 deletion S02-types/nil.t
Expand Up @@ -68,7 +68,9 @@ ok !Nil.new.defined, 'Nil.new is not defined';
{
sub f1($x) { } #OK
#?rakudo todo 'triage'
dies_ok { f1(Nil) }, 'param: dies for mandatory';
throws_like { f1(Nil) },
X::AdHoc, # XXX fix when this starts to fail
'param: dies for mandatory';

sub f2(Int $x?) { $x }
my $z;
Expand Down
4 changes: 3 additions & 1 deletion S02-types/num.t
Expand Up @@ -167,7 +167,9 @@ is(42_127_000, 42127000, 'multiple underscores ok');
is(42.0_1, 42.01, 'underscores in fraction ok');
is(4_2.01, 42.01, 'underscores in whole part ok');

eval_dies_ok('4_2._0_1', 'single underscores are not ok directly after the dot');
throws_like { EVAL '4_2._0_1' },
X::Method::NotFound,
'single underscores are not ok directly after the dot';
is(4_2.0_1, 42.01, 'single underscores are ok');

is 0_1, 1, "0_1 is parsed as 0d1";
Expand Down
4 changes: 3 additions & 1 deletion S02-types/pair.t
Expand Up @@ -261,7 +261,9 @@ Note, "non-chaining binary" was later renamed to "structural infix".
my ($key, $val) = <key val>;
my $pair = ($key => $val);

dies_ok { $pair.key = "KEY" }, "setting .key dies";
throws_like { $pair.key = "KEY" },
X::Assignment::RO,
"setting .key dies";
is $pair.key, "key", "attempt to set .key doesn't change the key";
#?niecza todo "setting .key changes original val!"
is $key, "key", "attempt to set .key does not change the original var either";
Expand Down

0 comments on commit 8120b6b

Please sign in to comment.