3 use Test::More tests => 135;
5 #use Pod::Simple::Debug (5);
7 #sub Pod::Simple::MANY_LINES () {1}
8 #sub Pod::Simple::PullParser::DEBUG () {1}
11 use Pod::Simple::PullParser;
14 my $p = Pod::Simple::PullParser->new;
15 $p->set_source( \( $_[0] ) );
17 while($t = $p->get_token) { push @t, $t }
18 print "# Count of tokens: ", scalar(@t), "\n";
19 print "# I.e., {", join("\n# + ",
20 map ref($_) . ": " . $_->dump, @t), "} \n";
26 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 @t = pump_it_up(qq{\n\nProk\n\n=head1 Things\n\n=cut\n\nBzorch\n\n});
31 is scalar( grep { ref $_ and $_->can('type') } @t), 5
33 fail "Wrong token count. Failing subsequent tests.\n";
34 for ( 2 .. 12 ) {fail}
36 is $t[0]->type, 'start';
37 is $t[1]->type, 'start';
38 is $t[2]->type, 'text';
39 is $t[3]->type, 'end';
40 is $t[4]->type, 'end';
42 is $t[0]->tagname, 'Document';
43 is $t[1]->tagname, 'head1';
44 is $t[2]->text, 'Things';
45 is $t[3]->tagname, 'head1';
46 is $t[4]->tagname, 'Document';
48 is $t[0]->attr('start_line'), '5';
49 is $t[1]->attr('start_line'), '5';
54 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 qq{Woowoo\n\n=over\n\n=item *\n\nStuff L<HTML::TokeParser>\n\n}
57 . qq{=item *\n\nThings I<like that>\n\n=back\n\n=cut\n\n}
61 not( is scalar( grep { ref $_ and $_->can('type') } @t) => 16 )
63 fail "Wrong token count. Failing subsequent tests.\n";
64 for ( 1 .. 32 ) {ok 0}
66 is $t[ 0]->type, 'start';
67 is $t[ 1]->type, 'start';
68 is $t[ 2]->type, 'start';
69 is $t[ 3]->type, 'text';
70 is $t[ 4]->type, 'start';
71 is $t[ 5]->type, 'text';
72 is $t[ 6]->type, 'end';
73 is $t[ 7]->type, 'end';
75 is $t[ 8]->type, 'start';
76 is $t[ 9]->type, 'text';
77 is $t[10]->type, 'start';
78 is $t[11]->type, 'text';
79 is $t[12]->type, 'end';
80 is $t[13]->type, 'end';
81 is $t[14]->type, 'end';
82 is $t[15]->type, 'end';
86 is $t[ 0]->tagname, 'Document';
87 is $t[ 1]->tagname, 'over-bullet';
88 is $t[ 2]->tagname, 'item-bullet';
89 is $t[ 3]->text, 'Stuff ';
90 is $t[ 4]->tagname, 'L';
91 is $t[ 5]->text, 'HTML::TokeParser';
92 is $t[ 6]->tagname, 'L';
93 is $t[ 7]->tagname, 'item-bullet';
95 is $t[ 8]->tagname, 'item-bullet';
96 is $t[ 9]->text, 'Things ';
97 is $t[10]->tagname, 'I';
98 is $t[11]->text, 'like that';
99 is $t[12]->tagname, 'I';
100 is $t[13]->tagname, 'item-bullet';
101 is $t[14]->tagname, 'over-bullet';
102 is $t[15]->tagname, 'Document';
104 is $t[4]->attr("type"), "pod";
108 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 print "# Testing unget_token\n";
112 my $p = Pod::Simple::PullParser->new;
113 $p->set_source( \qq{\nBzorch\n\n=pod\n\nLala\n\n\=cut\n} );
118 is $t && $t->type, 'start';
119 is $t && $t->tagname, 'Document';
120 print "# ungetting ($t).\n";
125 is $t && $t->type, 'start';
126 is $t && $t->tagname, 'Document';
130 is $t && $t->type, 'start';
131 is $t && $t->tagname, 'Para';
134 print "# ungetting (@to_save).\n";
135 $p->unget_token(@to_save);
140 is $t && $t->type, 'start';
141 is $t && $t->tagname, 'Document';
144 is $t && $t->type, 'start';
145 is $t && $t->tagname, 'Para';
152 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155 print "# Testing pullparsing from an arrayref\n";
156 my $p = Pod::Simple::PullParser->new;
158 $p->set_source( ['','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
161 while($t = $p->get_token) {
162 print "# Got a token: ", $t->dump, "\n#\n";
165 is scalar(@t), 5; # count of tokens
166 is $t[0]->type, 'start';
167 is $t[1]->type, 'start';
168 is $t[2]->type, 'text';
169 is $t[3]->type, 'end';
170 is $t[4]->type, 'end';
172 is $t[0]->tagname, 'Document';
173 is $t[1]->tagname, 'Para';
174 is $t[2]->text, 'Lala zaza';
175 is $t[3]->tagname, 'Para';
176 is $t[4]->tagname, 'Document';
180 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183 print "# Testing pullparsing from an arrayref with terminal newlines\n";
184 my $p = Pod::Simple::PullParser->new;
186 $p->set_source( [ map "$_\n",
187 '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
190 while($t = $p->get_token) {
191 print "# Got a token: ", $t->dump, "\n#\n";
194 is scalar(@t), 5; # count of tokens
195 is $t[0]->type, 'start';
196 is $t[1]->type, 'start';
197 is $t[2]->type, 'text';
198 is $t[3]->type, 'end';
199 is $t[4]->type, 'end';
201 is $t[0]->tagname, 'Document';
202 is $t[1]->tagname, 'Para';
203 is $t[2]->text, 'Lala zaza';
204 is $t[3]->tagname, 'Para';
205 is $t[4]->tagname, 'Document';
209 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210 our $temp_pod = "temp_$$.pod";
211 END { unlink "$temp_pod" }
213 print "# Testing pullparsing from a file\n";
214 my $p = Pod::Simple::PullParser->new;
216 open(OUT, ">$temp_pod") || die "Can't write-open $temp_pod: $!";
219 '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'
225 $p->set_source("$temp_pod");
228 while($t = $p->get_token) {
229 print "# Got a token: ", $t->dump, "\n#\n";
231 print "# That's token number ", scalar(@t), "\n";
233 is scalar(@t), 5; # count of tokens
234 is $t[0]->type, 'start';
235 is $t[1]->type, 'start';
236 is $t[2]->type, 'text';
237 is $t[3]->type, 'end';
238 is $t[4]->type, 'end';
240 is $t[0]->tagname, 'Document';
241 is $t[1]->tagname, 'Para';
242 is $t[2]->text, 'Lala zaza';
243 is $t[3]->tagname, 'Para';
244 is $t[4]->tagname, 'Document';
248 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
251 print "# Testing pullparsing from a glob\n";
252 my $p = Pod::Simple::PullParser->new;
254 open(IN, "<$temp_pod") || die "Can't read-open $temp_pod: $!";
258 while($t = $p->get_token) {
259 print "# Got a token: ", $t->dump, "\n#\n";
261 print "# That's token number ", scalar(@t), "\n";
263 is scalar(@t), 5; # count of tokens
264 is $t[0]->type, 'start';
265 is $t[1]->type, 'start';
266 is $t[2]->type, 'text';
267 is $t[3]->type, 'end';
268 is $t[4]->type, 'end';
270 is $t[0]->tagname, 'Document';
271 is $t[1]->tagname, 'Para';
272 is $t[2]->text, 'Lala zaza';
273 is $t[3]->tagname, 'Para';
274 is $t[4]->tagname, 'Document';
279 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
282 print "# Testing pullparsing from a globref\n";
283 my $p = Pod::Simple::PullParser->new;
285 open(IN, "<$temp_pod") || die "Can't read-open $temp_pod: $!";
286 $p->set_source(\*IN);
289 while($t = $p->get_token) {
290 print "# Got a token: ", $t->dump, "\n#\n";
292 print "# That's token number ", scalar(@t), "\n";
294 is scalar(@t), 5; # count of tokens
295 is $t[0]->type, 'start';
296 is $t[1]->type, 'start';
297 is $t[2]->type, 'text';
298 is $t[3]->type, 'end';
299 is $t[4]->type, 'end';
301 is $t[0]->tagname, 'Document';
302 is $t[1]->tagname, 'Para';
303 is $t[2]->text, 'Lala zaza';
304 is $t[3]->tagname, 'Para';
305 is $t[4]->tagname, 'Document';
310 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
313 print "# Testing pullparsing from a filehandle\n";
314 my $p = Pod::Simple::PullParser->new;
316 open(IN, "<$temp_pod") || die "Can't read-open $temp_pod: $!";
317 $p->set_source(*IN{IO});
320 while($t = $p->get_token) {
321 print "# Got a token: ", $t->dump, "\n#\n";
323 print "# That's token number ", scalar(@t), "\n";
325 is scalar(@t), 5; # count of tokens
326 is $t[0]->type, 'start';
327 is $t[1]->type, 'start';
328 is $t[2]->type, 'text';
329 is $t[3]->type, 'end';
330 is $t[4]->type, 'end';
332 is $t[0]->tagname, 'Document';
333 is $t[1]->tagname, 'Para';
334 is $t[2]->text, 'Lala zaza';
335 is $t[3]->tagname, 'Para';
336 is $t[4]->tagname, 'Document';