root/t/perl5/hash.t

Revision 20490, 1.2 kB (checked in by Auzon, 8 months ago)

s/use v6-alpha;$/use v6;/;
Also catching a few other mentions of v6-alpha.

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1use v6;
2
3use Test;
4
5plan(5);
6
7unless eval 'eval("1", :lang<perl5>)' {
8    skip_rest;
9    exit;
10}
11
12die unless
13eval(q/
14package My::Hash;
15use strict;
16
17sub new {
18    my ($class, $ref) = @_;
19    bless \$ref, $class;
20}
21
22sub hash {
23    my $self = shift;
24    return $$self;
25}
26
27sub my_keys {
28    my $self = shift;
29    return keys %{$$self};
30}
31
32sub my_exists {
33    my ($self, $idx) = @_;
34    return exists $$self->{$idx};
35}
36
37sub fetch {
38    my ($self, $idx) = @_;
39    return $$self->{$idx};
40}
41
42sub store {
43    my ($self, $idx, $val) = @_;
44    $$self->{$idx} = $val;
45}
46
47sub push {
48    my ($self, $val) = @_;
49}
50
511;
52/, :lang<perl5>);
53
54my $p5ha = eval('sub { My::Hash->new($_[0]) }', :lang<perl5>);
55my %hash = (5 => 'a', 6 => 'b', 7 => 'c', 8 => 'd');
56my $p5hash = $p5ha(\%hash);
57
58my $rethash = $p5hash.hash;
59my @keys = %hash.keys.sort;
60my @p5keys;
61try {
62    @p5keys = $p5hash.my_keys; # this doesn't even pass lives_ok ??
63    @p5keys .= sort;
64};
65
66is("{ @keys }", "{ @p5keys }");
67
68ok($p5hash.store(9, 'e'), 'can store');
69is(%hash{9}, 'e', 'store result');
70
71is($p5hash.fetch(5), 'a', 'fetch result');
72is($p5hash.my_exists(5), %hash.exists(5), 'exists');
73is($p5hash.my_exists(12), %hash.exists(12), 'nonexists fail', :todo<bug>);
Note: See TracBrowser for help on using the browser.