Skip to content

Commit

Permalink
Types should be C<> on their own page.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Mar 6, 2023
1 parent 96dbf7c commit 3a8c16c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions xt/rakudoc-types.rakutest
Expand Up @@ -10,6 +10,8 @@ Any other formatting code that refers to a type will fail the test; any C<>
that isn't inside of an L<> will fail, and any L<> that doesn't have a C<>
will fail. Links may end with an optional #id.
One exception: Referring to a type on its own page should only use C<>.
=end overview

use Test;
Expand Down Expand Up @@ -38,7 +40,7 @@ sub render-node($node) {
$result;
}

sub is-valid-type($node, $parent) {
sub is-valid-type($node, $parent, $file) {
# only care about I<>, C<>, L<>, etc.
return unless $node ~~ Pod::FormattingCode;

Expand All @@ -48,6 +50,18 @@ sub is-valid-type($node, $parent) {
my $type-colon = $type.subst('/', '::', :g);
return unless "doc/Type/$type-slash.rakudoc".IO.f;

if $file eq "doc/Type/$type-slash.rakudoc" {
# We are on the same page as this type. Don't link it, only C<> it.
if $node.type ne 'C' or $type ne $type-colon {
flunk "{render-node($node)} should be C<$type-colon> - self reference";
} elsif $parent ~~ Pod::FormattingCode {
flunk "$parent.type<{render-node($node)}> should be C<$type> - bad parent FormattingCode - self reference";
} else {
pass "{render-node($node)} OK - self reference";
}
return;
}

# Might be nested but we only report on the innermost here.
if $node.type ne 'C' {
flunk "{render-node($node)} should be L<C<$type>|/type/$type-colon>";
Expand Down Expand Up @@ -77,12 +91,12 @@ sub is-valid-type($node, $parent) {
}
}

sub walk-content($item, $parent) {
is-valid-type($item, $parent);
sub walk-content($item, $parent, $file) {
is-valid-type($item, $parent, $file);

next unless $item.can('contents');
for @($item.contents) -> $child {
walk-content($child, $item);
walk-content($child, $item, $file);
}
}

Expand All @@ -92,6 +106,6 @@ for @files -> $file {

# This emits pass or flunk for each local L<> found.
subtest $file => {
walk-content($_, Nil) for @chunks;
walk-content($_, Nil, $file) for @chunks;
}
}

0 comments on commit 3a8c16c

Please sign in to comment.