Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:perl6/roast
  • Loading branch information
Jimmy Zhuo committed Feb 23, 2011
2 parents 13da501 + ba7e504 commit dd8b0e0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 94 deletions.
61 changes: 61 additions & 0 deletions S02-builtin_data_types/array-shapes.t
@@ -0,0 +1,61 @@
use v6;
use Test;
plan(*);

# L<S09/Fixed-size arrays>

{
my @arr[*];
@arr[42] = "foo";
is(+@arr, 43, 'my @arr[*] autoextends like my @arr');
}

{
my @arr[7] = <a b c d e f g>;
is(@arr, [<a b c d e f g>], 'my @arr[num] can hold num things');
dies_ok({push @arr, 'h'}, 'adding past num items in my @arr[num] dies');
dies_ok({@arr[7]}, 'accessing past num items in my @arr[num] dies');
}

{
lives_ok({ my @arr\ [7]}, 'array with fixed size with unspace');
eval_dies_ok('my @arr.[8]', 'array with dot form dies');
eval_dies_ok('my @arr\ .[8]', 'array with dot form and unspace dies');
}

# L<S09/Typed arrays>

{
my @arr of Int = 1, 2, 3, 4, 5;
is(@arr, <1 2 3 4 5>, 'my @arr of Type works');
#?rakudo 2 todo "parametrization issues"
dies_ok({push @arr, 's'}, 'type constraints on my @arr of Type works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my @arr of Type works (2)');
}

{
my @arr[5] of Int = <1 2 3 4 5>;
is(@arr, <1 2 3 4 5>, 'my @arr[num] of Type works');

dies_ok({push @arr, 123}, 'boundary constraints on my @arr[num] of Type works');
pop @arr; # remove the last item to ensure the next ones are type constraints
dies_ok({push @arr, 's'}, 'type constraints on my @arr[num] of Type works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my @arr[num] of Type works (2)');
}

{
my int @arr = 1, 2, 3, 4, 5;
is(@arr, <1 2 3 4 5>, 'my Type @arr works');
dies_ok({push @arr, 's'}, 'type constraints on my Type @arr works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my Type @arr works (2)');
}

{
my int @arr[5] = <1 2 3 4 5>;
is(@arr, <1 2 3 4 5>, 'my Type @arr[num] works');

dies_ok({push @arr, 123}, 'boundary constraints on my Type @arr[num] works');
pop @arr; # remove the last item to ensure the next ones are type constraints
dies_ok({push @arr, 's'}, 'type constraints on my Type @arr[num] works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my Type @arr[num] works (2)');
}
94 changes: 1 addition & 93 deletions S02-builtin_data_types/array.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 104;
plan *;

#L<S02/Mutable types/Array>

Expand Down Expand Up @@ -250,98 +250,6 @@ my @array2 = ("test", 1, Mu);
dies_ok { @arr[$minus_one] := 42 }, "binding [-1] of a normal array is fatal";
}

# L<S09/Fixed-size arrays>

#?niecza skip "Array shapes"
{
my @arr[*];
@arr[42] = "foo";
is(+@arr, 43, 'my @arr[*] autoextends like my @arr');
}

#?niecza skip "Array shapes"
{
my @arr[7] = <a b c d e f g>;
is(@arr, [<a b c d e f g>], 'my @arr[num] can hold num things');
#?rakudo 2 todo "no bounds checking"
dies_ok({push @arr, 'h'}, 'adding past num items in my @arr[num] dies');
dies_ok({@arr[7]}, 'accessing past num items in my @arr[num] dies');
}

#?niecza skip "Array shapes"
{
lives_ok({ my @arr\ [7]}, 'array with fixed size with unspace');
eval_dies_ok('my @arr.[8]', 'array with dot form dies');
eval_dies_ok('my @arr\ .[8]', 'array with dot form and unspace dies');
}

# L<S09/Typed arrays>

#?niecza skip "Type declarations"
{
my @arr of Int = 1, 2, 3, 4, 5;
#?rakudo skip 'typed array recursion issue'
is(@arr, <1 2 3 4 5>, 'my @arr of Type works');
#?rakudo 2 todo "parametrization issues"
dies_ok({push @arr, 's'}, 'type constraints on my @arr of Type works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my @arr of Type works (2)');
}

#?niecza skip "Type declarations"
{
my @arr[5] of Int = <1 2 3 4 5>;
#?rakudo skip 'typed array recursion issue'
is(@arr, <1 2 3 4 5>, 'my @arr[num] of Type works');

#?rakudo todo "parametrization issues"
dies_ok({push @arr, 123}, 'boundary constraints on my @arr[num] of Type works');
pop @arr; # remove the last item to ensure the next ones are type constraints
#?rakudo 2 todo "parametrization issues"
dies_ok({push @arr, 's'}, 'type constraints on my @arr[num] of Type works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my @arr[num] of Type works (2)');
}

# syntax is currently reserved
# #?rakudo skip 'my @arr(-->Type) parsefail'
# {
# my @arr(-->Num) = <1 2.1 3.2>;
# is(@arr, <1 2.1 3.2>, 'my @arr[-->Type] works');
#
# lives_ok({push @arr, 4.3}, 'adding the proper type works');
# dies_ok({push @arr, 'string'}, 'type constraints on my @arr[-->Type] works');
# }
#
# #?rakudo skip 'my @arr[num-->Type] parsefail'
# {
# my @arr[3](-->Num) = <1 2.1 3.2>;
# is(@arr, <1 2.1 3.2>, 'my @arr[num-->Type] works');
#
# dies_ok({push @arr, 4.3}, 'boundary constraints work on my @arr[num-->Type]');
# pop @arr; # remove the last item to ensure the next ones are type constraints
# dies_ok({push @arr, 'string'}, 'type constraints on my @arr[-->Type] works');
# }

#?rakudo skip 'no native type int yet'
#?niecza skip "Type declarations"
{
my int @arr = 1, 2, 3, 4, 5;
is(@arr, <1 2 3 4 5>, 'my Type @arr works');
dies_ok({push @arr, 's'}, 'type constraints on my Type @arr works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my Type @arr works (2)');
}

#?rakudo skip 'my Type @arr[num] parsefail'
#?niecza skip "Type declarations"
{
my int @arr[5] = <1 2 3 4 5>;
is(@arr, <1 2 3 4 5>, 'my Type @arr[num] works');

dies_ok({push @arr, 123}, 'boundary constraints on my Type @arr[num] works');
pop @arr; # remove the last item to ensure the next ones are type constraints
dies_ok({push @arr, 's'}, 'type constraints on my Type @arr[num] works (1)');
dies_ok({push @arr, 4.2}, 'type constraints on my Type @arr[num] works (2)');
}

# RT #73308
#?niecza skip "Array.elems"
{
Expand Down
2 changes: 1 addition & 1 deletion S04-statements/try.t
Expand Up @@ -4,7 +4,7 @@ use Test;

# L<S04/"Statement parsing"/"or try {...}">

plan 17;
plan 18;

{
# simple try
Expand Down

0 comments on commit dd8b0e0

Please sign in to comment.