2 # Copyright (C) 2007-2008, Parrot Foundation.
7 t/oo/metamodel.t - test the metamodel for Parrot OO
11 % prove t/oo/metamodel.t
15 Tests the metamodel for the OO implementation.
20 load_bytecode 'Test/More.pbc'
22 .local pmc exports, curr_namespace, test_namespace
23 curr_namespace = get_namespace
24 test_namespace = get_namespace [ 'Test'; 'More' ]
25 exports = split " ", "plan ok is isa_ok skip todo"
26 test_namespace.'export_to'(curr_namespace, exports)
30 .local pmc class, init_args1
31 init_args1 = new 'Hash'
32 init_args1['name'] = 'Dog'
34 class = new "Class", init_args1
35 isa_ok(class, "Class", "created class isa Class")
37 is($P1, "Dog", "created a new class via Class")
39 is($P1, "Dog", "Class accessor doesn't destroy value")
41 class.'add_attribute'('bark')
42 class.'add_attribute'('ear')
43 class.'add_attribute'('tail')
45 attributes = class.'attributes'()
46 $I0 = exists attributes['bark']
47 ok($I0, "added attribute to the class")
49 $I0 = exists attributes['tail']
50 ok($I0, "added second attribute to the class")
51 unless $I0 goto no_tail_attribute
52 $P1 = attributes['tail']
55 todo($I0, "tail attribute has a type", "not implemented")
56 # is($S1,'Str', "tail attribute has a type")
57 goto end_tail_attrib_test
59 fail("tail attribute doesn't exist")
64 $I0 = issame $P0, class
65 ok($I0, "get_class can find the class")
67 $P0 = class.'new'( 'bark' => "Wooof", 'tail' => 'long' )
68 $P1 = getattribute $P0, "tail"
70 ok($I0, "got back a tail attribute object")
71 unless $I0 goto FAILTAIL
72 is($P1, "long", "tail attribute has expected value")
78 $P1 = getattribute $P0, "bark"
80 ok($I0, "got back a bark attribute object")
82 is($P1, "Wooof", "bark attribute has expected value")
88 todo(0, "new opcode makes working objects", "not implemented")
91 # isa_ok($P0, "Dog", "new opcode makes working objects")
97 .sub _accessor :method
99 .param pmc value :optional
101 unless got_value goto get_attr
102 setattribute self, attrib, value
105 rv = getattribute self, attrib
109 .sub init_pmc :vtable :method
111 # Iterate over the constructor arguments, calling the accessor for each
115 unless it goto iter_end
124 .param pmc bark :optional
125 .param int got_bark :opt_flag
127 rv = self.'_accessor'( "bark", bark, got_bark )
132 .param pmc tail :optional
133 .param int got_tail :opt_flag
135 rv = self.'_accessor'( "tail", tail, got_tail )
143 # vim: expandtab shiftwidth=4 ft=pir: