Skip to content

Commit c6caf04

Browse files
committed
Added test for consisten header capitalization
1 parent 016acef commit c6caf04

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

t/08-headings.t

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env perl6
2+
3+
use v6;
4+
use lib 'lib';
5+
use Test;
6+
BEGIN plan :skip-all<Test applicable to git checkout only> unless '.git'.IO.e;
7+
use Test-Files;
8+
9+
my @files = Test-Files.documents;
10+
11+
plan +@files;
12+
13+
# these words don't have to be capitalized
14+
# my $stopwords = /^()$/;
15+
16+
for @files -> $file {
17+
my @lines;
18+
my @examples;
19+
my $line-no = 0;
20+
for $file.IO.lines -> $line {
21+
$line-no++;
22+
if $line.starts-with("=TITLE") or $line.starts-with("=SUBTITLE") {
23+
# ignore first word like "=TITLE"
24+
my $title = $line.substr($line.index(' ') + 1);
25+
# ignore "class X::TypeCheck" and the like
26+
$title ~~ s:g/^ ( class | role | module ) \s+ \S+//;
27+
$title ~~ s:g/ <|w> ( Perl 6 | AST | EVAL | PRE | POST | Whatever ) //;
28+
$title ~~ s:g/ <|w> <[ C ]> \< .*? \> //;
29+
# ignore known classes like "Real" which are capitalized
30+
my @words = $title ~~ m:g/ <|w> ( <:Lu> \S+ ) /;
31+
for @words -> $word {
32+
# if it exists, skip it
33+
try {
34+
::($word);
35+
$title ~~ s:g/ << $word >> //;
36+
}
37+
}
38+
# sentence case: all lowercase, titlecase for first character
39+
if $title !~~ $title.lc.tc {
40+
@lines.push($line-no);
41+
@examples.push($title);
42+
}
43+
}
44+
}
45+
if @lines {
46+
flunk "$file has inconsisten capitalised headings on lines: {@lines}\n"
47+
~ @examples.join("\n");
48+
} else {
49+
pass "$file capitalises headings consistently ";
50+
}
51+
}
52+
53+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)