Skip to content

Commit 01725c6

Browse files
committed
Check WHEREFOREs in leading test
1 parent a370b4f commit 01725c6

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

S26-documentation/why-leading.t

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use Test;
2-
plan 116;
2+
plan 139;
33

44
my $pod_index = 0;
55

@@ -13,6 +13,7 @@ is Simple.WHY.leading, 'simple case';
1313
ok !Simple.WHY.trailing.defined;
1414
is ~Simple.WHY, 'simple case', 'stringifies correctly';
1515

16+
ok $=pod[$pod_index].WHEREFORE === Simple;
1617
is ~$=pod[$pod_index++], 'simple case';
1718

1819
#| giraffe
@@ -22,7 +23,9 @@ class Outer {
2223
}
2324
}
2425

26+
ok $=pod[$pod_index].WHEREFORE === Outer;
2527
is ~$=pod[$pod_index++], 'giraffe';
28+
ok $=pod[$pod_index].WHEREFORE === Outer::Inner;
2629
is ~$=pod[$pod_index++], 'zebra';
2730

2831
is Outer.WHY.contents, 'giraffe';
@@ -44,8 +47,11 @@ module foo {
4447
}
4548
}
4649

50+
ok $=pod[$pod_index].WHEREFORE === foo;
4751
is ~$=pod[$pod_index++], 'a module';
52+
ok $=pod[$pod_index].WHEREFORE === foo::bar;
4853
is ~$=pod[$pod_index++], 'a package';
54+
ok $=pod[$pod_index].WHEREFORE === foo::bar;
4955
is ~$=pod[$pod_index++], 'and a class';
5056

5157
is foo.WHY.contents, 'a module';
@@ -64,6 +70,7 @@ ok !foo::bar::baz.WHY.trailing.defined;
6470
#| yellow
6571
sub marine {}
6672

73+
ok $=pod[$pod_index].WHEREFORE === &marine;
6774
is ~$=pod[$pod_index++], 'yellow';
6875

6976
is &marine.WHY.contents, 'yellow';
@@ -74,6 +81,7 @@ ok !&marine.WHY.trailing.defined;
7481
#| pink
7582
sub panther {}
7683

84+
ok $=pod[$pod_index].WHEREFORE === &panther;
7785
is ~$=pod[$pod_index++], 'pink';
7886

7987
is &panther.WHY.contents, 'pink';
@@ -90,20 +98,24 @@ class Sheep {
9098
method roar { 'roar!' }
9199
}
92100

101+
my $wool-attr = Sheep.^attributes.grep({ .name eq '$!wool' })[0];
102+
my $roar-method = Sheep.^find_method('roar');
103+
104+
ok $=pod[$pod_index].WHEREFORE === Sheep;
93105
is ~$=pod[$pod_index++], 'a sheep';
106+
ok $=pod[$pod_index].WHEREFORE === $wool-attr;
94107
is ~$=pod[$pod_index++], 'usually white';
108+
ok $=pod[$pod_index].WHEREFORE === $roar-method;
95109
is ~$=pod[$pod_index++], 'not too scary';
96110

97111
is Sheep.WHY.contents, 'a sheep';
98112
ok Sheep.WHY.WHEREFORE === Sheep, 'class WHEREFORE matches';
99113
is Sheep.WHY.leading, 'a sheep';
100114
ok !Sheep.WHY.trailing.defined;
101-
my $wool-attr = Sheep.^attributes.grep({ .name eq '$!wool' })[0];
102115
ok $wool-attr.WHY.WHEREFORE === $wool-attr, 'attr WHEREFORE matches';
103116
is $wool-attr.WHY, 'usually white';
104117
is $wool-attr.WHY.leading, 'usually white';
105118
ok !$wool-attr.WHY.trailing.defined;
106-
my $roar-method = Sheep.^find_method('roar');
107119
is $roar-method.WHY.contents, 'not too scary';
108120
ok $roar-method.WHY.WHEREFORE === $roar-method, 'method WHEREFORE matches';
109121
is $roar-method.WHY.leading, 'not too scary';
@@ -119,13 +131,15 @@ ok &oursub.WHY.WHEREFORE === &oursub, 'our sub WHEREFORE matches';
119131
is &oursub.WHY.leading, 'our works too', 'works for our subs';
120132
ok !&oursub.WHY.trailing.defined;
121133

134+
ok $=pod[$pod_index].WHEREFORE === &oursub;
122135
is ~$=pod[$pod_index++], 'our works too';
123136

124137
# two subs in a row
125138

126139
#| one
127140
sub one {}
128141

142+
ok $=pod[$pod_index].WHEREFORE === &one;
129143
is ~$=pod[$pod_index++], 'one';
130144

131145
#| two
@@ -139,16 +153,19 @@ ok &two.WHY.WHEREFORE === &two, 'sub WHEREFORE matches';
139153
is &two.WHY.leading, 'two';
140154
ok !&two.WHY.trailing.defined;
141155

156+
ok $=pod[$pod_index].WHEREFORE === &two;
142157
is ~$=pod[$pod_index++], 'two';
143158

144159
#| that will break
145160
sub first {}
146161

162+
ok $=pod[$pod_index].WHEREFORE === &first;
147163
is ~$=pod[$pod_index++], 'that will break';
148164

149165
#| that will break
150166
sub second {}
151167

168+
ok $=pod[$pod_index].WHEREFORE === &second;
152169
is ~$=pod[$pod_index++], 'that will break';
153170

154171
is &first.WHY.contents, 'that will break';
@@ -167,13 +184,15 @@ ok &third.WHY.WHEREFORE === &third, 'sub WHEREFORE matches';
167184
is &third.WHY.leading, 'trailing space here';
168185
ok !&third.WHY.trailing.defined;
169186

187+
ok $=pod[$pod_index].WHEREFORE === &third;
170188
is ~$=pod[$pod_index++], 'trailing space here';
171189

172190
sub has-parameter(
173191
#| documented
174192
Str $param
175193
) {}
176194

195+
ok $=pod[$pod_index].WHEREFORE === &has-parameter.signature.params[0];
177196
is ~$=pod[$pod_index++], 'documented';
178197

179198
ok !&has-parameter.WHY.defined, 'has-parameter should have no docs' or diag(&has-parameter.WHY);
@@ -188,6 +207,7 @@ sub has-two-params(
188207
Int $second
189208
) {}
190209

210+
ok $=pod[$pod_index].WHEREFORE === &has-parameter.signature.params[0];
191211
is ~$=pod[$pod_index++], 'documented';
192212

193213
ok !&has-two-params.WHY.defined;
@@ -204,7 +224,9 @@ sub both-documented(
204224
Int $second
205225
) {}
206226

227+
ok $=pod[$pod_index].WHEREFORE === &both-documented.signature.params[0];
207228
is ~$=pod[$pod_index++], 'documented';
229+
ok $=pod[$pod_index].WHEREFORE === &both-documented.signature.params[1];
208230
is ~$=pod[$pod_index++], 'I too, am documented';
209231

210232
ok !&both-documented.WHY.defined;
@@ -223,6 +245,7 @@ sub has-anon-param(
223245
Str $
224246
) {}
225247

248+
ok $=pod[$pod_index].WHEREFORE === &has-anon-param.signature.params[0];
226249
is ~$=pod[$pod_index++], 'leading';
227250

228251
my $param = &has-anon-param.signature.params[0];
@@ -236,10 +259,11 @@ class DoesntMatter {
236259
$arg
237260
) {}
238261
}
262+
$param = DoesntMatter.^find_method('m').signature.params[0];
239263

264+
ok $=pod[$pod_index].WHEREFORE === $param;
240265
is ~$=pod[$pod_index++], 'invocant comment';
241266

242-
$param = DoesntMatter.^find_method('m').signature.params[0];
243267
is $param.WHY, 'invocant comment', 'invocant comments should work';
244268

245269
is $=pod.elems, $pod_index;

0 commit comments

Comments
 (0)