2
# Copyright (C) 2007-2008, The Perl Foundation.
7
t/pmc/perl6multisub-type.t - Type based dispatch tests
11
% prove t/pmc/perl6multisub-type.t
15
Tests for type based dispatch using the Perl 6 MultiSub PMC.
19
.loadlib 'perl6_group'
22
.include 'include/test_more.pir'
23
load_bytecode "perl6.pbc"
34
$P0 = new "Perl6MultiSub"
35
$P1 = get_global 'basic_class_1'
36
'attach_sig'($P1, 'Int')
38
$P1 = get_global 'basic_class_2'
39
'attach_sig'($P1, 'Junction')
45
is($I0, 1, 'dispatch on class')
48
is($I0, 2, 'dispatch on class')
61
# Create a couple of roles.
63
R1 = '!keyword_role'('R1')
65
R2 = '!keyword_role'('R2')
69
$P0 = new "Perl6MultiSub"
70
$P1 = get_global 'role_1'
71
'attach_sig'($P1, 'R1')
73
$P1 = get_global 'role_2'
74
'attach_sig'($P1, 'R2')
77
# Couple of classes that do the roles.
78
.local pmc C1, C2, p6meta
79
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
80
C1 = p6meta.'new_class'('C1', 'parent'=>'Any')
81
p6meta.'add_role'(R1, 'to'=>C1)
82
C2 = p6meta.'new_class'('C2', 'parent'=>'Any')
83
p6meta.'add_role'(R2, 'to'=>C2)
88
is($I0, 1, 'dispatch on a role')
91
is($I0, 2, 'dispatch on a role')
106
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
107
p6meta.'new_class'('Paper', 'parent'=>'Any')
108
p6meta.'new_class'('Scissors', 'parent'=>'Any')
109
p6meta.'new_class'('Stone', 'parent'=>'Any')
111
$P0 = new "Perl6MultiSub"
112
$P1 = get_global 'ordered_class_1'
113
'attach_sig'($P1, 'Any', 'Any')
115
$P1 = get_global 'ordered_class_2'
116
'attach_sig'($P1, 'Paper', 'Stone')
118
$P1 = get_global 'ordered_class_3'
119
'attach_sig'($P1, 'Stone', 'Scissors')
121
$P1 = get_global 'ordered_class_4'
122
'attach_sig'($P1, 'Scissors', 'Paper')
125
.local pmc paper, scissors, stone
126
paper = get_hll_global 'Paper'
127
paper = paper.'new'()
128
scissors = get_hll_global 'Scissors'
129
scissors = scissors.'new'()
130
stone = get_hll_global 'Stone'
131
stone = stone.'new'()
133
$I0 = $P0(paper, paper)
134
is($I0, 0, 'topological sorting')
135
$I0 = $P0(paper, scissors)
136
is($I0, 0, 'topological sorting')
137
$I0 = $P0(paper, stone)
138
is($I0, 1, 'topological sorting')
139
$I0 = $P0(scissors, paper)
140
is($I0, 1, 'topological sorting')
141
$I0 = $P0(scissors, scissors)
142
is($I0, 0, 'topological sorting')
143
$I0 = $P0(scissors, stone)
144
is($I0, 0, 'topological sorting')
145
$I0 = $P0(stone, paper)
146
is($I0, 0, 'topological sorting')
147
$I0 = $P0(stone, scissors)
148
is($I0, 1, 'topological sorting')
149
$I0 = $P0(stone, stone)
150
is($I0, 0, 'topological sorting')
152
.sub 'ordered_class_1'
157
.sub 'ordered_class_2'
162
.sub 'ordered_class_3'
167
.sub 'ordered_class_4'
175
.param pmc types :slurpy
181
$P0 = new 'Signature'
182
$P1 = new 'Perl6Array'
183
setattribute $P0, "@!params", $P1
187
unless it goto param_loop_end
190
type = get_hll_global $S0
191
$P2 = new 'Perl6Hash'
192
$P2["nom_type"] = type
193
$P2["multi_invocant"] = true
198
setprop sub, '$!signature', $P0
205
# vim: expandtab shiftwidth=4 ft=pir: