Skip to content

Commit bb4981c

Browse files
committed
Add test to avoid non linked URLs.
1 parent 03ebc96 commit bb4981c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

t/22-links-not-links.rakutest

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env raku
2+
3+
=begin overview
4+
5+
Avoid I<bare> URLs that are not links; URLs should go inside C<L<>> markup.
6+
7+
=end overview
8+
9+
use experimental :rakuast;
10+
11+
use Test;
12+
use RakuDoc::Test::Files;
13+
14+
my @files = RakuDoc::Test::Files.pods;
15+
16+
if @files {
17+
plan +@files;
18+
} else {
19+
plan :skip-all<No rakudoc files specified>
20+
}
21+
22+
sub walk($node) {
23+
my @children;
24+
if $node ~~ RakuAST::Doc::Paragraph {
25+
@children = $node.atoms;
26+
} elsif $node ~~ RakuAST::Doc::Block {
27+
return if $node.type eq 'code'|'implicit-code'|'comment'|'table';
28+
@children = $node.paragraphs;
29+
} elsif $node ~~ RakuAST::Doc::Markup {
30+
return if $node.letter eq 'L';
31+
@children = $node.atoms;
32+
} else {
33+
# If this hits, need to adapt test
34+
flunk "new node type: $node.^name";
35+
}
36+
37+
for @children -> $child {
38+
if $child ~~ Str {
39+
if $child ~~ / $<url>=[ 'http' 's'? '://' <-[/]>* '/'? ] / {
40+
flunk "URL found: $<url>";
41+
}
42+
} else {
43+
walk($child);
44+
}
45+
}
46+
}
47+
48+
for @files -> $file {
49+
%*ENV<RAKUDO_RAKUAST>=1;
50+
subtest $file => {
51+
for $file.IO.slurp.AST.rakudoc -> $pod {
52+
walk($pod);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)