summaryrefslogtreecommitdiff
path: root/t/dsl/pod.t
blob: b15a9642ad581512d9aee24c4b295083e5a20eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use strict;
use warnings;
use Test::More;
use Config;

use Dancer2::Core::DSL;
use Pod::Simple::SimpleTree;

{
    package App;
    use Dancer2;
}

my $dsl_keywords = Dancer2::Core::DSL->new(app => App->to_app)->dsl_keywords;

isa_ok($dsl_keywords, 'HASH', 'Check whether keywords are present');

my $dir = $ENV{AUTOPKGTEST_TMP} ? $Config{vendorlib} : 'lib';
my $podpa = Pod::Simple::SimpleTree->new->parse_file($dir . '/Dancer2/Manual/Keywords.pod')->root;

my $in_section = 0;

for my $entry (@$podpa) {
    if (ref($entry) eq 'ARRAY') {
        if ($entry->[0] eq 'head1') {
            if ($entry->[2] eq 'DSL KEYWORDS') {
                # keywords following that entry
                $in_section = 1;
            }
            elsif ($in_section == 1) {
                # end of keywords section
                last;
            }
        }

        if ($in_section && $entry->[0] eq 'head2') {
            # get the bare keyword and compare with the authoritative list
            my $title = $entry->[2];
            $title =~ /^\s*(\S+)/;
            my $keyword = $1;

            if (exists $dsl_keywords->{$keyword}) {
                $dsl_keywords->{$keyword}->{found} = $entry->[1]->{startline};
            }
        }
    }
}

# go through the authoritative list and test we have a corresponding POD entry
for my $keyword ( sort keys %$dsl_keywords ) { 
    ok( exists $dsl_keywords->{$keyword}->{found}, "Keyword $keyword is documented in Dancer2::Manual::Keywords" );
}

done_testing;