Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 154 lines (131 sloc) 5.756 kb
288e046 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
cc341e3 Moritz Lenz RT #111646, slurpies => infinite .count
moritz authored
5 plan 52;
288e046 [t] and [t/spec]
moritz authored
6
7 # L<S06/Required parameters/method:>
8 sub a_zero () { };
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
9 sub a_one ($a) { }; #OK not used
10 sub a_two ($a, $b) { }; #OK not used
11 sub a_three ($a, $b, @c) { }; #OK not used
12 sub a_four ($a, $b, @c, %d) { }; #OK not used
288e046 [t] and [t/spec]
moritz authored
13
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
14 sub o_zero ($x?, $y?) { }; #OK not used
15 sub o_one ($x, :$y) { }; #OK not used
16 sub o_two ($x, :$y!, :$z) { }; #OK not used
288e046 [t] and [t/spec]
moritz authored
17
18 is &a_zero.arity, 0, '0 arity &sub';
19 is &a_one.arity, 1, '1 arity &sub';
20 is &a_two.arity, 2, '2 arity &sub';
21 is &a_three.arity, 3, '3 arity &sub';
22 is &a_four.arity, 4, '4 arity &foo';
23
b1c8167 Will Coleda pugs fudge
coke authored
24 #?pugs 5 skip '.count'
8ea59c5 [t/spec] tests for .count on subs
moritz authored
25 is &a_zero.count, 0, '0 count &sub';
26 is &a_one.count, 1, '1 count &sub';
27 is &a_two.count, 2, '2 count &sub';
28 is &a_three.count, 3, '3 count &sub';
29 is &a_four.count, 4, '4 count &foo';
30
b1c8167 Will Coleda pugs fudge
coke authored
31 #?pugs 3 todo
288e046 [t] and [t/spec]
moritz authored
32 is &o_zero.arity, 0, 'arity 0 sub with optional params';
33 is &o_one.arity, 1, 'arity 1 sub with optional params';
fc90fd1 Jonathan Worthington .arity and .count ignore nameds.
jnthn authored
34 is &o_two.arity, 1, 'arity with optional and required named params';
288e046 [t] and [t/spec]
moritz authored
35
b1c8167 Will Coleda pugs fudge
coke authored
36 #?pugs 3 skip '.count'
8ea59c5 [t/spec] tests for .count on subs
moritz authored
37 is &o_zero.count, 2, 'count on sub with optional params';
fc90fd1 Jonathan Worthington .arity and .count ignore nameds.
jnthn authored
38 is &o_one.count, 1, 'count on sub with optional params';
39 is &o_two.count, 1, 'count on sub with optional and required named params';
8ea59c5 [t/spec] tests for .count on subs
moritz authored
40
b1c8167 Will Coleda pugs fudge
coke authored
41 #?pugs skip 'parsefail'
502162b [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
moritz authored
42 {
43 sub b_zero () { };
8ea59c5 [t/spec] tests for .count on subs
moritz authored
44 sub b_one ($) { };
45 sub b_two ($, $) { };
46 sub b_three ($, $, @) { };
47 sub b_four ($, $, @, %) { };
48 is &b_zero.arity, 0, '0 arity &sub (sigils only)';
49 is &b_one.arity, 1, '1 arity &sub (sigils only)';
50 is &b_two.arity, 2, '2 arity &sub (sigils only)';
51 is &b_three.arity, 3, '3 arity &sub (sigils only)';
52 is &b_four.arity, 4, '4 arity &foo (sigils only)';
502162b [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
moritz authored
53
54 }
55
288e046 [t] and [t/spec]
moritz authored
56 # It's not really specced in what way (*@slurpy_params) should influence
57 # .arity. Also it's unclear what the result of &multisub.arity is.
58 # See the thread "&multisub.arity?" on p6l started by Ingo Blechschmidt for
59 # details:
60 # L<http://thread.gmane.org/gmane.comp.lang.perl.perl6.language/4915>
61
62 {
63 is ({ $^a }.arity), 1,
64 "block with one placeholder var has .arity == 1";
b1c8167 Will Coleda pugs fudge
coke authored
65 #?pugs 4 skip "is multi"
288e046 [t] and [t/spec]
moritz authored
66 is (-> $a { $a }.arity), 1,
67 "pointy block with one placeholder var has .arity == 1";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
68 is { $^a,$^b }.arity, 2,
288e046 [t] and [t/spec]
moritz authored
69 "block with two placeholder vars has .arity == 2";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
70 is (-> $a, $b { $a,$b }).arity, 2,
288e046 [t] and [t/spec]
moritz authored
71 "pointy block with two placeholder vars has .arity == 2";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
72 is { $^a,$^b,$^c }.arity, 3,
288e046 [t] and [t/spec]
moritz authored
73 "block with three placeholder vars has .arity == 3";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
74 is (-> $a, $b, $c { $a,$b,$c }).arity, 3,
288e046 [t] and [t/spec]
moritz authored
75 "pointy block with three placeholder vars has .arity == 3";
b1c8167 Will Coleda pugs fudge
coke authored
76
77 #?pugs 6 skip ".count"
8ea59c5 [t/spec] tests for .count on subs
moritz authored
78 is ({ $^a }.count), 1,
79 "block with one placeholder var has .count == 1";
80 is (-> $a { $a }.count), 1,
81 "pointy block with one placeholder var has .count == 1";
82 is { $^a,$^b }.count, 2,
83 "block with two placeholder vars has .count == 2";
84 is (-> $a, $b { $a,$b }).count, 2,
85 "pointy block with two placeholder vars has .count == 2";
86 is { $^a,$^b,$^c }.count, 3,
87 "block with three placeholder vars has .count == 3";
88 is (-> $a, $b, $c { $a,$b,$c }).count, 3,
89 "pointy block with three placeholder vars has .count == 3";
288e046 [t] and [t/spec]
moritz authored
90 }
91
b1c8167 Will Coleda pugs fudge
coke authored
92 #?pugs skip "is multi"
288e046 [t] and [t/spec]
moritz authored
93 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
94 is { my $k; $^a }.arity, 1, #OK not used
288e046 [t] and [t/spec]
moritz authored
95 "additional my() vars don't influence .arity calculation (1-1)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
96 is { my $k; $^a,$^b }.arity, 2, #OK not used
288e046 [t] and [t/spec]
moritz authored
97 "additional my() vars don't influence .arity calculation (1-2)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
98 is { my $k; $^a,$^b,$^c }.arity, 3, #OK not used
288e046 [t] and [t/spec]
moritz authored
99 "additional my() vars don't influence .arity calculation (1-3)";
8ea59c5 [t/spec] tests for .count on subs
moritz authored
100
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
101 is { my $k; $^a }.count, 1, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
102 "additional my() vars don't influence .count calculation (1-1)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
103 is { my $k; $^a,$^b }.count, 2, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
104 "additional my() vars don't influence .count calculation (1-2)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
105 is { my $k; $^a,$^b,$^c }.count, 3, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
106 "additional my() vars don't influence .count calculation (1-3)";
288e046 [t] and [t/spec]
moritz authored
107 }
108
b1c8167 Will Coleda pugs fudge
coke authored
109 #?pugs skip 'is multi'
288e046 [t] and [t/spec]
moritz authored
110 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
111 is { $^a; my $k }.arity, 1, #OK not used
288e046 [t] and [t/spec]
moritz authored
112 "additional my() vars don't influence .arity calculation (2-1)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
113 is { $^a,$^b; my $k }.arity, 2, #OK not used
288e046 [t] and [t/spec]
moritz authored
114 "additional my() vars don't influence .arity calculation (2-2)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
115 is { $^a,$^b,$^c; my $k }.arity, 3, #OK not used
288e046 [t] and [t/spec]
moritz authored
116 "additional my() vars don't influence .arity calculation (2-3)";
8ea59c5 [t/spec] tests for .count on subs
moritz authored
117
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
118 is { $^a; my $k }.count, 1, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
119 "additional my() vars don't influence .count calculation (2-1)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
120 is { $^a,$^b; my $k }.count, 2, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
121 "additional my() vars don't influence .count calculation (2-2)";
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
122 is { $^a,$^b,$^c; my $k }.count, 3, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
123 "additional my() vars don't influence .count calculation (2-3)";
288e046 [t] and [t/spec]
moritz authored
124 }
9543526 [t/spec] tests for RT #63744
moritz authored
125
126 # used to be a bug in Rakudo, RT #63744
b1c8167 Will Coleda pugs fudge
coke authored
127 #?pugs skip 'parsefail'
9543526 [t/spec] tests for RT #63744
moritz authored
128 {
129 sub indirect-count(Code $c) { +$c.signature.params; }
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
130 my $tester = -> $a, $b, $c? { ... }; #OK not used
9543526 [t/spec] tests for RT #63744
moritz authored
131 is +$tester.signature.params, 3, '+$obj.signature.params work';
132 is +$tester.signature.params, indirect-count($tester),
133 '... also when passed to a sub first';
134 }
a3d3a00 [t/spec] Add a test to show bug #66868
kyle authored
135
b1c8167 Will Coleda pugs fudge
coke authored
136 #?pugs todo
a238bb3 Moritz Lenz remove bogus test
moritz authored
137 dies_ok { eval("a_zero( 'hello', 'world' )") }, 'no matching sub signature';
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
138
b1c8167 Will Coleda pugs fudge
coke authored
139 #?pugs skip 'parsefail'
afae36a Moritz Lenz .count and .arity on multis (RT #76646
moritz authored
140 {
141 my proto sub a($, $?) { * }
142 my multi sub a($) { 1 }
143 my multi sub a($, $) { 2 }
144 is &a.count, 2, '&multi.count';
145 is &a.arity, 1, '&multi.arity';
146 }
147
cc341e3 Moritz Lenz RT #111646, slurpies => infinite .count
moritz authored
148 # RT #111646
395bd85 Will Coleda pugs fudge (new tests)
coke authored
149 #?pugs 2 skip '.count'
cc341e3 Moritz Lenz RT #111646, slurpies => infinite .count
moritz authored
150 is (-> *@a { }).count, Inf, 'slurpy positional causes infinite count';
151 is (-> *%a { }).count, 0, 'slurpy named causes no count change';
152
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
153 # vim: ft=perl6
Something went wrong with that request. Please try again.