~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to t/nqp/52-vtable.t

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! nqp
2
 
 
3
 
class ABC {
4
 
    method () is parrot_vtable('get_number') { 123.0 }
5
 
    method () is parrot_vtable('get_string') { 'abc' }
6
 
}
7
 
 
8
 
plan(10);
9
 
 
10
 
my $abc := ABC.new;
11
 
ok($abc == 123,   "get_number vtable works");
12
 
ok($abc eq 'abc', "get_string vtable works");
13
 
 
14
 
class DEF is ABC {
15
 
    method () is parrot_vtable('get_string') { 'def' }
16
 
}
17
 
 
18
 
my $def := DEF.new;
19
 
ok($def == 123,   "get_number vtable from parent works");
20
 
ok($def eq 'def', "get_string vtable as override works");
21
 
 
22
 
class Hashy {
23
 
    has %!h;
24
 
    method init() { %!h := nqp::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')  { nqp::existskey(%!h, $k)      }
28
 
    method ($k)     is parrot_vtable('delete_keyed_str')  { nqp::deletekey(%!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(nqp::existskey($h, 'foo'), 'exists');
36
 
nqp::deletekey($h, 'foo');
37
 
ok(!nqp::existskey($h, 'foo'), 'delete');
38
 
 
39
 
class Arrayy {
40
 
    has @!a;
41
 
    method init() { @!a := nqp::list() }
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')  { nqp::existspos(@!a, $k)      }
45
 
    method ($k)     is parrot_vtable('delete_keyed_int')  { nqp::deletepos(@!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(nqp::existspos($a, 0), 'exists');
53
 
nqp::deletepos($a, 0);
54
 
ok(!nqp::existspos($a, 0), 'delete');