2 # Copyright (C) 2007-2010, 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 .include 'test_more.pir'
24 .local pmc class, init_args1
25 init_args1 = new 'Hash'
26 init_args1['name'] = 'Dog'
28 class = new "Class", init_args1
29 isa_ok(class, "Class", "created class isa Class")
31 is($P1, "Dog", "created a new class via Class")
33 is($P1, "Dog", "Class accessor doesn't destroy value")
35 class.'add_attribute'('bark')
36 class.'add_attribute'('ear')
37 class.'add_attribute'('tail')
39 attributes = class.'attributes'()
40 $I0 = exists attributes['bark']
41 ok($I0, "added attribute to the class")
43 $I0 = exists attributes['tail']
44 ok($I0, "added second attribute to the class")
45 unless $I0 goto no_tail_attribute
46 $P1 = attributes['tail']
49 todo($I0, "tail attribute has a type", "not implemented: TT #1618")
50 # is($S1,'Str', "tail attribute has a type")
51 goto end_tail_attrib_test
53 fail("tail attribute doesn't exist")
58 $I0 = issame $P0, class
59 ok($I0, "get_class can find the class")
61 $P0 = class.'new'( 'bark' => "Wooof", 'tail' => 'long' )
62 $P1 = getattribute $P0, "tail"
64 ok($I0, "got back a tail attribute object")
65 unless $I0 goto FAILTAIL
66 is($P1, "long", "tail attribute has expected value")
72 $P1 = getattribute $P0, "bark"
74 ok($I0, "got back a bark attribute object")
76 is($P1, "Wooof", "bark attribute has expected value")
84 isa_ok($P0, "Dog", "new opcode makes working objects")
95 .sub _accessor :method
97 .param pmc value :optional
99 unless got_value goto get_attr
100 setattribute self, attrib, value
103 rv = getattribute self, attrib
107 .sub init_pmc :vtable :method
109 # Iterate over the constructor arguments, calling the accessor for each
113 unless it goto iter_end
122 .param pmc bark :optional
123 .param int got_bark :opt_flag
125 rv = self.'_accessor'( "bark", bark, got_bark )
130 .param pmc tail :optional
131 .param int got_tail :opt_flag
133 rv = self.'_accessor'( "tail", tail, got_tail )
141 # vim: expandtab shiftwidth=4 ft=pir: