Skip to content
Newer
Older
100644 77 lines (58 sloc) 1.21 KB
2c8a840 [t] move perl5/* to spec/S01-perl-5-integration/
moritz authored
1 use v6;
2
3 use Test;
4
5 plan(5);
6
7 unless eval 'eval("1", :lang<perl5>)' {
8 skip_rest;
9 exit;
10 }
11
12 die unless
13 eval(q/
14 package My::Hash;
15 use strict;
16
17 sub new {
18 my ($class, $ref) = @_;
19 bless \$ref, $class;
20 }
21
22 sub hash {
23 my $self = shift;
24 return $$self;
25 }
26
27 sub my_keys {
28 my $self = shift;
29 return keys %{$$self};
30 }
31
32 sub my_exists {
33 my ($self, $idx) = @_;
34 return exists $$self->{$idx};
35 }
36
37 sub fetch {
38 my ($self, $idx) = @_;
39 return $$self->{$idx};
40 }
41
42 sub store {
43 my ($self, $idx, $val) = @_;
44 $$self->{$idx} = $val;
45 }
46
47 sub push {
48 my ($self, $val) = @_;
49 }
50
51 1;
52 /, :lang<perl5>);
53
54 my $p5ha = eval('sub { My::Hash->new($_[0]) }', :lang<perl5>);
55 my %hash = (5 => 'a', 6 => 'b', 7 => 'c', 8 => 'd');
56 my $p5hash = $p5ha(\%hash);
57
58 my $rethash = $p5hash.hash;
59 my @keys = %hash.keys.sort;
60 my @p5keys;
61 try {
62 @p5keys = $p5hash.my_keys; # this doesn't even pass lives_ok ??
63 @p5keys .= sort;
64 };
65
66 is("{ @keys }", "{ @p5keys }");
67
68 ok($p5hash.store(9, 'e'), 'can store');
69 is(%hash{9}, 'e', 'store result');
70
71 is($p5hash.fetch(5), 'a', 'fetch result');
72 is($p5hash.my_exists(5), %hash.exists(5), 'exists');
aa50b55 Replace Pugs todo with fudge command as per deprecated-syntax.pod
kyle authored
73 #?pugs todo 'bug'
74 is($p5hash.my_exists(12), %hash.exists(12), 'nonexists fail');
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
75
76 # vim: ft=perl6
Something went wrong with that request. Please try again.