File: keys_values.t

package info (click to toggle)
rakudo 2016.12-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,200 kB
  • ctags: 1,323
  • sloc: perl: 45,091; java: 2,524; ansic: 1,761; cpp: 152; sh: 17; makefile: 15
file content (30 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
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
use v6.c;

use Test;

plan 8;

=begin description

Basic C<keys> and C<values> tests for arrays, see S32.

=end description

my @array = <a b c d>;

# L<S32::Containers/"Array"/=item keys>
is(~@array.keys, '0 1 2 3', '@arrays.keys works');
is(~keys(@array), '0 1 2 3', 'keys(@array) works');
is(+@array.keys, +@array, 'we have the same number of keys as elements in the array');

# L<S32::Containers/"Array"/=item values>
is(~@array.values, 'a b c d', '@array.values works');
is(~values(@array), 'a b c d', 'values(@array) works');
is(+@array.values, +@array, 'we have the same number of values as elements in the array');

my $v := @array.values.Array;
$v.shift; $v.shift;
is($v.elems, 2, "shifting .values removes an element...");
is(@array.elems, 4, "...while leaving original list alone.");

# vim: ft=perl6