9 Basic C<pairs> tests, see S32::Containers.
13 # L<S32::Containers/"Hash"/=item pairs>
16 my %hash = (a => 1, b => 2, c => 3);
18 ok((@pairs = %hash.pairs), "pairs on hashes");
19 ok((@pairs = @pairs.sort), 'Can sort list of pairs');
20 is +@pairs, 3, "pairs on hashes returned the correct number of elems";
22 skip 6, "skipped tests which depend on a test which failed";
24 is @pairs[0].key, "a", "value of pair returned by hash.pairs was correct (1)";
25 is @pairs[1].key, "b", "value of pair returned by hash.pairs was correct (2)";
26 is @pairs[2].key, "c", "value of pair returned by hash.pairs was correct (3)";
27 is @pairs[0].value, 1, "key of pair returned by hash.pairs was correct (1)";
28 is @pairs[1].value, 2, "key of pair returned by hash.pairs was correct (2)";
29 is @pairs[2].value, 3, "key of pair returned by hash.pairs was correct (3)";
33 # Following stated by Larry on p6l
37 ok((@pairs = $pair.pairs), "pairs on a pair");
38 is +@pairs, 1, "pairs on a pair returned one elem";
40 skip 2, "skipped tests which depend on a test which failed";
42 is @pairs[0].key, "a", "key of pair returned by pair.pairs";
43 is @pairs[0].value, 1, "value of pair returned by pair.pairs";
47 # This next group added by Darren Duncan following discovery while debugging ext/Locale-KeyedText:
49 my $hash_of_2_pairs = {'a'=>'b','c'=>'d'};
50 my $hash_of_1_pair = {'a'=>'b'};
51 #?pugs 2 todo 'feature'
52 is( $hash_of_2_pairs.pairs.sort.join( ',' ), "a\tb,c\td",
53 "pairs() on 2-elem hash, 1-depth joined");
54 is( $hash_of_1_pair.pairs.sort.join( ',' ), "a\tb",
55 "pairs() on 1-elem hash, 1-depth joined");
56 is( $hash_of_2_pairs.pairs.sort.map({ .key~'='~.value }).join( ',' ), 'a=b,c=d',
57 "pairs() on 2-elem hash, 2-depth joined" );
58 is( try { $hash_of_1_pair.pairs.sort.map({ .key~'='~.value }).join( ',' ) }, 'a=b',
59 "pairs() on 1-elem hash, 2-depth joined" );
63 my %hash = (:a(1), :b(2), :c(3));
65 lives_ok { for %hash.pairs -> $pair {
67 } }, 'aliases returned by %hash.pairs should be rw (1)';
69 #?rakudo todo "Rakudo seems to make a copy rather than a reference"
70 is %hash<b>, 102, 'aliases returned by %hash.pairs should be rw (2)';
77 lives_ok { for $pair.pairs -> $p {
79 } }, 'aliases returned by $pair.value should be rw (1)';
81 is $pair.value, 142, 'aliases returned by $pair.kv should be rw (2)';