@@ -5,7 +5,7 @@ class ABC {
5
5
method () is parrot_vtable(' get_string' ) { ' abc' }
6
6
}
7
7
8
- plan (4 );
8
+ plan (10 );
9
9
10
10
my $ abc := ABC. new ;
11
11
ok ($ abc == 123 , " get_number vtable works" );
@@ -18,3 +18,37 @@ class DEF is ABC {
18
18
my $ def := DEF. new ;
19
19
ok ($ def == 123 , " get_number vtable from parent works" );
20
20
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