Debian Codegraph @

t/05_pod_detailed.t

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 5;
6 use Pod::Abstract;
7
8 my $pod = q~
9 =head1 NAME
10
11 Example - Example POD document.
12
13 =head1 DESCRIPTION
14
15 This is an I<example POD document> for testing purposes. We are going
16 to parse and traverse it.
17
18 =head1 FUNCTIONS
19
20 =head2 example_method
21
22 my $v = sample_call($x); # Gives a result
23
24 This would be typical for a perl module.
25
26 =over
27
28 =item *
29
30 This would be a bulleted list
31
32 =item *
33
34 Explaining what to do
35
36 =over
37
38 =item 1
39
40 This one would be a nested numbered list
41
42 =item 2
43
44 This would also
45
46 =back
47
48 =item *
49
50 Back in the bullets
51
52 =back
53
54 =cut
55
56 sub sample_call {
57 # Do some code. This is a "cut" node.
58 }
59
60 =head2 begin/end
61
62 =begin markdown
63
64 * I wouldn't expect this to be parsed internally by Pod::Abstract.
65 * This would instead be a single text node - POD sequences like C<this>
66 are just normal text.
67
68 =end
69
70 =begin :special
71
72 These I<should> be parsed.
73
74 It's a special trait of POD that : at the begining of a POD block is
75 meant to have its internals parsed as POD.
76
77 =end
78
79 =for example this would not be parsed.
80
81 =for :example but B<this> would.
82
83 =head1 SEE ALSO
84
85 L<perlfunc/wantarray> is a link to a function inside a standard document.
86
87 L<Pod::Abstract> is a link to a module.
88
89 L<Pod::Abstract/load_string> is a link to a section in a module.
90
91 L<perlsyn/"For Loops"> is a quoted section name.
92
93 L<Pod Abstract is Great|Pod::Abstract> has link text.
94
95 L<Test Hyperlink|https://metacpan.org/>
96
97 =cut
98
99 ~;
100
101 my $pa = Pod::Abstract->load_string($pod);
102
103 ok($pa, "Sample POD parsed");
104
105 subtest 'Document Links' => sub {
106 my @links = $pa->select('//:L');
107 ok(@links == 6, "Found 5 links in the document");
108
109 my $li = $links[0]->link_info;
110 is( $li->{text}, 'perlfunc', 'Perlfunc link had expected text' );
111 is( $li->{section}, 'wantarray', 'And linked to "wantarray"' );
112
113 $li = $links[1]->link_info;
114 is( $li->{text}, 'Pod::Abstract', 'Module link is Pod::Abstract' );
115 is( $li->{document}, 'Pod::Abstract', 'Document is same');
116 ok( !$li->{section}, 'Section is not defined');
117
118 $li = $links[2]->link_info;
119 is( $li->{text}, 'Pod::Abstract', 'Module link is Pod::Abstract' );
120 is( $li->{document}, 'Pod::Abstract', 'Document is same');
121 is( $li->{section}, 'load_string', 'Section is load_string');
122
123 $li = $links[3]->link_info;
124 is( $li->{text}, 'perlsyn', 'Link text is perlsyn');
125 is( $li->{section}, '"For Loops"', 'Section is "For Loops"');
126
127 $li = $links[4]->link_info;
128 is( $li->{text}, "Pod Abstract is Great", 'Link text is "Pod Abstract is Great"');
129 is( $li->{document}, "Pod::Abstract", 'Document is Pod::Abstract');
130
131 $li = $links[5]->link_info;
132 is( $li->{text}, 'Test Hyperlink', 'Link text is "Test Hyperlink"' );
133 is( $li->{url}, 'https://metacpan.org/', 'Link to metacpan' );
134 };
135
136 subtest 'begin/end and custom nodes' => sub {
137 # =begin/=end
138 my ($hdg) = $pa->select(q{/head1[@heading eq 'FUNCTIONS']/head2[@heading eq 'begin/end']});
139 my @special = $hdg->select(qq{/begin[. eq ':special']});
140 ok( @special == 1, "Found 1 ':special'");
141
142 # : means the inner parts should be parsed - there should be 7
143 # nodes in there if we flatten them out
144 my @s_inner = $special[0]->select('//'); # All nodes.
145 ok( @s_inner == 7, "7 inner nodes in the :special node");
146 ok( (grep { $_->type eq ':I' } @s_inner), "Found the italic node");
147
148 my @markdown = $hdg->select(qq{/begin[. eq 'markdown']});
149 ok( @markdown == 1, "Found 1 'markdown'");
150
151 # This shouldn't be parsed, it should be only one text node.
152 my @m_inner = $markdown[0]->select('//');
153 ok( @m_inner == 1, "Only one inner node");
154 is( $m_inner[0]->type, ':text', "Inner node is a text node" );
155
156 # =for
157 my @for = $hdg->select(q{/for});
158 ok( @for == 2, "Two :fors");
159
160 my @for_ex = $hdg->select(q{/for[. eq 'example']});
161 ok( @for_ex == 1, "One =for example" );
162
163 my @fenodes = $for_ex[0]->select("//");
164 ok( @fenodes == 1 && $fenodes[0]->type eq ':text', "And it's just one text node - not parsed");
165
166 my @for_ex2 = $hdg->select(q{/for[. eq ':example']});
167 ok( @for_ex2 == 1, "One =for :example" );
168
169 my @fenodes2 = $for_ex2[0]->select("//");
170 ok( @fenodes2 == 4, "Four nodes, looks parsed" );
171 ok( (grep {$_->type eq ':B'} @fenodes2), "Found the bold text" );
172
173 };
174
175 subtest 'List Items' => sub {
176 my @list_numbered = $pa->select("//head2/over//over/item");
177 ok(@list_numbered == 2, "Found 2 nested list items");
178 };
179
180 subtest 'Round Trip' => sub {
181 is($pod, $pa->pod, "Document round-trip with no changes");
182 };
183
184 1;