Skip to content

Commit 4ac46b5

Browse files
committed
Add test for Type link formatting.
Accepted formatting is, e.g.: L<C<Int>|/type/Int>
1 parent a4b34ba commit 4ac46b5

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

xt/rakudoc-types.rakutest

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env raku
2+
3+
=begin overview
4+
5+
When referring to items that are types, the required format is:
6+
7+
L<C<Thing>|/type/Thing>
8+
9+
Any other formatting code that refers to a type will fail the test; any C<>
10+
that isn't inside of an L<> will fail, and any L<> that doesn't have a C<>
11+
will fail.
12+
13+
Note - correctly formed entries will not be reported as passing subtests - only
14+
items that fail are reported.
15+
16+
=end overview
17+
18+
use Test;
19+
use lib $*PROGRAM.parent(2).child('lib');
20+
21+
use Test-Files;
22+
use Pod::Convenience;
23+
24+
my @files = Test-Files.pods;
25+
26+
if @files {
27+
plan +@files;
28+
} else {
29+
plan :skip-all<No rakudoc files specified>
30+
}
31+
32+
sub is-valid-type($node, $parent) {
33+
# only care about I<>, C<>, L<>, etc.
34+
return unless $node ~~ Pod::FormattingCode;
35+
36+
# Does this match a type?
37+
my $type = $node.contents.join('');
38+
return unless "doc/Type/$type.rakudoc".IO.f;
39+
40+
if $node.type ne 'C' {
41+
flunk $node.type ~ '<' ~ $type ~ "> should be L<C<$type>|/type/$type>";
42+
return;
43+
}
44+
45+
if $parent === Nil or ! ($parent ~~ Pod::FormattingCode) {
46+
flunk $node.type ~ '<' ~ $type ~ "> should be L<C<$type>|/type/$type> - bad parent class: {$parent.^name}";
47+
return;
48+
}
49+
50+
if $parent.type ne 'L' {
51+
flunk $parent.type ~ '<C<' ~ $type ~ ">> should be L<C<$type>|/type/$type> - bad parent FormattingCode";
52+
return;
53+
} elsif $parent.meta ne "/type/$type" {
54+
flunk 'L<C<' ~ $type ~ '|' ~ $parent.meta~ ">> should be L<C<$type>|/type/$type> - bad link";
55+
} else {
56+
pass "$type reference correctly formatted.";
57+
}
58+
59+
}
60+
61+
sub walk-content($item, $parent) {
62+
is-valid-type($item, $parent);
63+
64+
next unless $item.can('contents');
65+
for @($item.contents) -> $child {
66+
walk-content($child, $item);
67+
}
68+
}
69+
70+
for @files -> $file {
71+
my @chunks = extract-pod($file).contents;
72+
73+
# This emits pass or flunk for each local L<> found.
74+
subtest $file => {
75+
walk-content($_, Nil) for @chunks;
76+
}
77+
}

0 commit comments

Comments
 (0)