/
protoobject.t
152 lines (112 loc) · 3.24 KB
/
protoobject.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
# $Id$
=head1 NAME
t/library/protoobject.t - testing Protoobject.pir
=head1 SYNOPSIS
% prove t/library/protoobject.t
=head1 DESCRIPTION
This test exercises the protoobject/Protomaker implementations.
=cut
.sub main :main
load_bytecode 'Protoobject.pbc'
.include 'test_more.pir'
plan(13)
test_basic_load()
test_type_of_protoobject()
test_type_of_ns_based_protoobject()
test_protoobject_symbol_1()
test_protoobject_symbol_2()
test_protoobject_symbol_for_classes()
test_new_subclass_for_classes()
test_new_subclass_with_attrs()
test_method_new_on_protoobject()
.end
.sub test_basic_load
$P0 = get_hll_global 'Protomaker'
$S0 = typeof $P0
is($S0, 'Protomaker', 'basic load')
.end
.sub test_type_of_protoobject
$P0 = get_hll_global 'Protomaker'
$P1 = newclass 'XYZ'
$P2 = $P0.'new_proto'($P1)
$S0 = typeof $P2
is($S0, 'XYZ', 'type of protoobject')
.end
.sub test_type_of_ns_based_protoobject
$P0 = get_hll_global 'Protomaker'
$P1 = newclass ['Foo';'Bar1']
$P2 = $P0.'new_proto'($P1)
$S0 = typeof $P2
is($S0, 'Foo;Bar1', 'type of ns-based protoobject')
.end
.sub test_protoobject_symbol_1
$P0 = get_hll_global 'Protomaker'
$P1 = newclass ['Foo';'Bar2']
$P2 = $P0.'new_proto'($P1)
$P2 = get_hll_global ['Foo'], 'Bar2'
$S0 = typeof $P2
is($S0, 'Foo;Bar2', 'protoobject symbol 1')
.end
.sub test_protoobject_symbol_2
$P0 = get_hll_global 'Protomaker'
$P1 = newclass 'Foo'
$P2 = $P0.'new_proto'($P1)
$P2 = get_hll_global 'Foo'
$S0 = typeof $P2
is($S0, 'Foo', 'protoobject symbol 2')
.end
.sub test_protoobject_symbol_for_classes
$P0 = get_hll_global 'Protomaker'
$P1 = newclass 'Foo::Bar3'
$P2 = $P0.'new_proto'($P1)
$P2 = get_hll_global ['Foo'], 'Bar3'
$S0 = typeof $P2
is($S0, 'Foo::Bar3', 'protoobject symbol for :: classes')
.end
.sub test_new_subclass_for_classes
$P0 = get_hll_global 'Protomaker'
$P1 = get_class 'Hash'
$P0.'new_subclass'($P1, 'Foo::Bar4')
$P2 = new 'Foo::Bar4'
$S0 = typeof $P2
is($S0, 'Foo::Bar4', 'new_subclass for :: classes')
$P2 = get_hll_global ['Foo'], 'Bar4'
$S0 = typeof $P2
is($S0, 'Foo::Bar4', 'new_subclass for :: classes')
.end
.sub test_new_subclass_with_attrs
.local pmc protomaker, hashclass, attrs
protomaker = get_hll_global 'Protomaker'
hashclass = get_class 'Hash'
attrs = split ' ', '$a $b $c $d'
protomaker.'new_subclass'(hashclass, 'Foo::Bar', attrs :flat)
.local pmc object, it
object = new 'Foo::Bar'
it = iter attrs
iter_loop:
unless it goto iter_end
$P0 = shift it
$S0 = $P0
setattribute object, $S0, $P0
$P1 = getattribute object, $S0
is($P1, $P0,'new_subclass with attrs')
goto iter_loop
iter_end:
.end
.sub test_method_new_on_protoobject
$P0 = newclass 'Foo1'
.local pmc protomaker
protomaker = get_hll_global 'Protomaker'
protomaker.'new_proto'('Foo1')
$P0 = get_hll_global 'Foo1'
$P1 = $P0.'new'()
$S0 = typeof $P1
is($S0, 'Foo1', 'method "new" on protoobject')
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: