Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 63c4f609dd
Fetching contributors…

Cannot retrieve contributors at this time

file 91 lines (76 sloc) 2.843 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
use v6;

use Test;

plan 34;

{
    my @array = 11 .. 15;

    is(@array.elems, 5, 'array has 5 elements');
    is(@array[0], 11, 'first value is 11');
    #?rakudo skip "whatever star"
    is(@array[*-1], 15, 'last value is 15');
    # 3[0] etc. should *not* work, but (3,)[0] should.
    # That's similar as with the .kv issue we've had: 3.kv should fail, but
    # (3,).kv should work.
    dies_ok({@array[0][0]}, 'scalar is not implicitly array', :todo<bug>);
}

{
    my @array = [ 11 .. 15 ];

    is(@array[0].elems, 5, 'arrayref has 5 elements');
    is(@array[0][0], 11, 'first element in arrayref is 11');

    #?rakudo skip "whatever star"
    is(@array[0][*-1], 15, 'last element in arrayref is 15');
}

{
    my @array = [ 11 .. 15 ], [ 21 .. 25 ], [ 31 .. 35 ];

    is(@array[0].elems, 5, 'first arrayref has 5 elements');
    is(@array[1].elems, 5, 'second arrayref has 5 elements');
    is(@array[0][0], 11, 'first element in first arrayref is 11');
    #?rakudo skip "whatever star"
    is(@array[0][*-1], 15, 'last element in first arrayref is 15');
    is(@array[1][0], 21, 'first element in second arrayref is 21');
    #?rakudo 3 skip "whatever star"
    is(@array[1][*-1], 25, 'last element in second arrayref is 25');
    is(@array[*-1][0], 31, 'first element in last arrayref is 31');
    is(@array[*-1][*-1], 35, 'last element in last arrayref is 35');
}

{
    my %hash = (k1 => [ 11 .. 15 ]);

    is(%hash<k1>.elems, 5, 'k1 has 5 elements');
    is(%hash<k1>[0], 11, 'first element in k1 is 11');
    #?rakudo skip "whatever star"
    is(%hash<k1>[*-1], 15, 'last element in k1 is 15');
    #?rakudo skip "Can't compare to undef (?)"
    is(%hash<12>, undef, 'nothing at key "12"');
}

{
    my %hash = (k1 => [ 11 .. 15 ], k2 => [ 21 .. 25 ]);

    is(%hash<k1>.elems, 5, 'k1 has 5 elements');
    is(%hash<k2>.elems, 5, 'k2 has 5 elements');
    is(%hash<k1>[0], 11, 'first element in k1 is 11');
    #?rakudo skip "whatever star"
    is(%hash<k1>[*-1], 15, 'last element in k1 is 15');
    is(%hash<k2>[0], 21, 'first element in k1 is 21');
    #?rakudo skip "whatever star"
    is(%hash<k2>[*-1], 25, 'last element in k1 is 25');
    is(%hash<12>, undef, 'nothing at key "12"');
    is(%hash<22>, undef, 'nothing at key "22"');
}

#?rakudo skip "prefix:<\\>"
{
    my @a;
    push @a, 1;
    is(@a.elems, 1, 'Simple push works');
    push @a, [];
    is(@a.elems, 2, 'Arrayref literal not flattened');
    push @a, {};
    is(@a.elems, 3, 'Hashref literal not flattened');
    my @foo;
    push @a, \@foo;
    is(@a.elems, 4, 'Arrayref not flattened');
    my %foo;
    push @a, \%foo;
    is(@a.elems, 5, 'Hashref not flattened');
    push @a, @foo;
    is(@a.elems, 5, 'Array flattened');
    push @a, %foo;
    is(@a.elems, 5, 'Hash flattened');
}
    
Something went wrong with that request. Please try again.