Skip to content

Commit a22edc2

Browse files
committed
more vtable tests
1 parent f10b936 commit a22edc2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

t/nqp/52-vtable.t

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ABC {
55
method () is parrot_vtable('get_string') { 'abc' }
66
}
77

8-
plan(4);
8+
plan(10);
99

1010
my $abc := ABC.new;
1111
ok($abc == 123, "get_number vtable works");
@@ -18,3 +18,37 @@ class DEF is ABC {
1818
my $def := DEF.new;
1919
ok($def == 123, "get_number vtable from parent works");
2020
ok($def eq 'def', "get_string vtable as override works");
21+
22+
class Hashy {
23+
has %!h;
24+
method init() { %!h := pir::new('Hash') }
25+
method ($k) is parrot_vtable('get_pmc_keyed_str') { %!h{$k}}
26+
method ($k, $v) is parrot_vtable('set_pmc_keyed_str') { %!h{$k} := $v }
27+
method ($k) is parrot_vtable('exists_keyed_str') { pir::exists(%!h, $k) }
28+
method ($k) is parrot_vtable('delete_keyed_str') { pir::delete(%!h, $k) }
29+
}
30+
31+
my $h := Hashy.new; $h.init();
32+
33+
$h<foo> := 'bar';
34+
ok($h<foo> eq 'bar', '{set,get}_pmc_keyed_str');
35+
ok(pir::exists($h, 'foo'), 'exists');
36+
pir::delete($h, 'foo');
37+
ok(!pir::exists($h, 'foo'), 'delete');
38+
39+
class Arrayy {
40+
has @!a;
41+
method init() { @!a := pir::new('ResizablePMCArray') }
42+
method ($k) is parrot_vtable('get_pmc_keyed_int') { @!a{$k}}
43+
method ($k, $v) is parrot_vtable('set_pmc_keyed_int') { @!a{$k} := $v }
44+
method ($k) is parrot_vtable('exists_keyed_int') { pir::exists(@!a, $k) }
45+
method ($k) is parrot_vtable('delete_keyed_int') { pir::delete(@!a, $k) }
46+
}
47+
48+
my $a := Arrayy.new; $a.init();
49+
50+
$a[0] := 'bar';
51+
ok($a[0] eq 'bar', '{set,get}_pmc_keyed_int');
52+
ok(pir::exists($a, 0), 'exists');
53+
pir::delete($a, 0);
54+
ok(!pir::exists($a, 0), 'delete');

0 commit comments

Comments
 (0)