-
Notifications
You must be signed in to change notification settings - Fork 138
/
multisub.t
98 lines (77 loc) · 1.85 KB
/
multisub.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
#!./parrot
# Copyright (C) 2001-2008, Parrot Foundation.
=head1 NAME
t/pmc/multisub.t - Multi Sub PMCs
=head1 SYNOPSIS
% prove t/pmc/multisub.t
=head1 DESCRIPTION
Tests the creation and invocation of Perl6 multi subs.
=cut
.sub main :main
.include 'test_more.pir'
plan( 8 )
$P0 = new ['MultiSub']
$I0 = defined $P0
ok($I0, "create PMC")
$I0 = elements $P0
is($I0, 0, "multisubs start empty")
$S0 = foo()
is($S0, "testing no arg", "no argument variant")
$S0 = foo("hello")
is($S0, "testing hello", "single string variant")
$S0 = foo(5)
is($S0, "testing 5", "single int variant")
$S0 = foo(42, "goodbye")
is($S0, "testing 42, goodbye", "int and string variant")
## Test handling of :flat parameters.
$P0 = new ['ResizablePMCArray']
push $P0, 42
push $P0, "goodbye"
$S0 = foo($P0 :flat)
is($S0, "testing 42, goodbye", "Int and String :flat")
## Now try double :flat
$P1 = new ['ResizablePMCArray']
push $P1, 42
$P2 = new ['ResizablePMCArray']
push $P2, "goodbye"
$S0 = foo($P1 :flat, $P2 :flat)
is($S0, "testing 42, goodbye", "Int and String double :flat")
.end
.sub foo :multi()
.return ('testing no arg')
.end
.sub foo :multi(string)
.param string bar
$S0 = "testing " . bar
.return ($S0)
.end
.sub foo :multi(int)
.param int bar
$S1 = bar
$S0 = "testing " . $S1
.return ($S0)
.end
.sub foo :multi(int, string)
.param int bar
.param string baz
$S1 = bar
$S0 = "testing " . $S1
$S0 .= ", "
$S0 .= baz
.return ($S0)
.end
.sub foo :multi(Integer, String)
.param pmc bar
.param pmc baz
$S1 = bar
$S2 = baz
$S0 = "testing " . $S1
$S0 .= ", "
$S0 .= $S2
.return ($S0)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: