Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 130 lines (109 sloc) 5.149 kb
288e046 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
a3d3a00 [t/spec] Add a test to show bug #66868
kyle authored
5 plan 48;
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
8ea59c5 [t/spec] tests for .count on subs
moritz authored
24 is &a_zero.count, 0, '0 count &sub';
25 is &a_one.count, 1, '1 count &sub';
26 is &a_two.count, 2, '2 count &sub';
27 is &a_three.count, 3, '3 count &sub';
28 is &a_four.count, 4, '4 count &foo';
29
288e046 [t] and [t/spec]
moritz authored
30 is &o_zero.arity, 0, 'arity 0 sub with optional params';
31 is &o_one.arity, 1, 'arity 1 sub with optional params';
32 is &o_two.arity, 2, 'arity with optional and required named params';
33
8ea59c5 [t/spec] tests for .count on subs
moritz authored
34 is &o_zero.count, 2, 'count on sub with optional params';
35 is &o_one.count, 2, 'count on sub with optional params';
36 is &o_two.count, 3, 'count on sub with optional and required named params';
37
502162b [t/spec] exercise bare "oh I feel so Haskell" sigils in signatures
moritz authored
38 {
39 sub b_zero () { };
8ea59c5 [t/spec] tests for .count on subs
moritz authored
40 sub b_one ($) { };
41 sub b_two ($, $) { };
42 sub b_three ($, $, @) { };
43 sub b_four ($, $, @, %) { };
44 is &b_zero.arity, 0, '0 arity &sub (sigils only)';
45 is &b_one.arity, 1, '1 arity &sub (sigils only)';
46 is &b_two.arity, 2, '2 arity &sub (sigils only)';
47 is &b_three.arity, 3, '3 arity &sub (sigils only)';
48 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
49
50 }
51
288e046 [t] and [t/spec]
moritz authored
52 # It's not really specced in what way (*@slurpy_params) should influence
53 # .arity. Also it's unclear what the result of &multisub.arity is.
54 # See the thread "&multisub.arity?" on p6l started by Ingo Blechschmidt for
55 # details:
56 # L<http://thread.gmane.org/gmane.comp.lang.perl.perl6.language/4915>
57
58 {
59 is ({ $^a }.arity), 1,
60 "block with one placeholder var has .arity == 1";
61 is (-> $a { $a }.arity), 1,
62 "pointy block with one placeholder var has .arity == 1";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
63 is { $^a,$^b }.arity, 2,
288e046 [t] and [t/spec]
moritz authored
64 "block with two placeholder vars has .arity == 2";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
65 is (-> $a, $b { $a,$b }).arity, 2,
288e046 [t] and [t/spec]
moritz authored
66 "pointy block with two placeholder vars has .arity == 2";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
67 is { $^a,$^b,$^c }.arity, 3,
288e046 [t] and [t/spec]
moritz authored
68 "block with three placeholder vars has .arity == 3";
d26e373 [t/spec]: Unfudge arity tests on blocks and pointy subs.
pmichaud authored
69 is (-> $a, $b, $c { $a,$b,$c }).arity, 3,
288e046 [t] and [t/spec]
moritz authored
70 "pointy block with three placeholder vars has .arity == 3";
8ea59c5 [t/spec] tests for .count on subs
moritz authored
71
72 is ({ $^a }.count), 1,
73 "block with one placeholder var has .count == 1";
74 is (-> $a { $a }.count), 1,
75 "pointy block with one placeholder var has .count == 1";
76 is { $^a,$^b }.count, 2,
77 "block with two placeholder vars has .count == 2";
78 is (-> $a, $b { $a,$b }).count, 2,
79 "pointy block with two placeholder vars has .count == 2";
80 is { $^a,$^b,$^c }.count, 3,
81 "block with three placeholder vars has .count == 3";
82 is (-> $a, $b, $c { $a,$b,$c }).count, 3,
83 "pointy block with three placeholder vars has .count == 3";
288e046 [t] and [t/spec]
moritz authored
84 }
85
86 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
87 is { my $k; $^a }.arity, 1, #OK not used
288e046 [t] and [t/spec]
moritz authored
88 "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
89 is { my $k; $^a,$^b }.arity, 2, #OK not used
288e046 [t] and [t/spec]
moritz authored
90 "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
91 is { my $k; $^a,$^b,$^c }.arity, 3, #OK not used
288e046 [t] and [t/spec]
moritz authored
92 "additional my() vars don't influence .arity calculation (1-3)";
8ea59c5 [t/spec] tests for .count on subs
moritz authored
93
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
94 is { my $k; $^a }.count, 1, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
95 "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
96 is { my $k; $^a,$^b }.count, 2, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
97 "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
98 is { my $k; $^a,$^b,$^c }.count, 3, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
99 "additional my() vars don't influence .count calculation (1-3)";
288e046 [t] and [t/spec]
moritz authored
100 }
101
102 {
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
103 is { $^a; my $k }.arity, 1, #OK not used
288e046 [t] and [t/spec]
moritz authored
104 "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
105 is { $^a,$^b; my $k }.arity, 2, #OK not used
288e046 [t] and [t/spec]
moritz authored
106 "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
107 is { $^a,$^b,$^c; my $k }.arity, 3, #OK not used
288e046 [t] and [t/spec]
moritz authored
108 "additional my() vars don't influence .arity calculation (2-3)";
8ea59c5 [t/spec] tests for .count on subs
moritz authored
109
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
110 is { $^a; my $k }.count, 1, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
111 "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
112 is { $^a,$^b; my $k }.count, 2, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
113 "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
114 is { $^a,$^b,$^c; my $k }.count, 3, #OK not used
8ea59c5 [t/spec] tests for .count on subs
moritz authored
115 "additional my() vars don't influence .count calculation (2-3)";
288e046 [t] and [t/spec]
moritz authored
116 }
9543526 [t/spec] tests for RT #63744
moritz authored
117
118 # used to be a bug in Rakudo, RT #63744
119 {
120 sub indirect-count(Code $c) { +$c.signature.params; }
8dc7d4b [t/spec] mark various tests that intentionally declare things that are n...
lwall authored
121 my $tester = -> $a, $b, $c? { ... }; #OK not used
9543526 [t/spec] tests for RT #63744
moritz authored
122 is +$tester.signature.params, 3, '+$obj.signature.params work';
123 is +$tester.signature.params, indirect-count($tester),
124 '... also when passed to a sub first';
125 }
a3d3a00 [t/spec] Add a test to show bug #66868
kyle authored
126
127 dies_ok { a_zero( 'hello', 'world' ) }, 'no matching sub signature';
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
128
129 # vim: ft=perl6
Something went wrong with that request. Please try again.