10 BEGIN { plan tests => 136 };
12 #use Pod::Simple::Debug (5);
14 #sub Pod::Simple::MANY_LINES () {1}
15 #sub Pod::Simple::PullParser::DEBUG () {1}
18 use Pod::Simple::PullParser;
21 my $p = Pod::Simple::PullParser->new;
22 $p->set_source( \( $_[0] ) );
24 while($t = $p->get_token) { push @t, $t }
25 print "# Count of tokens: ", scalar(@t), "\n";
26 print "# I.e., {", join("\n# + ",
27 map ref($_) . ": " . $_->dump, @t), "} \n";
33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 @t = pump_it_up(qq{\n\nProk\n\n=head1 Things\n\n=cut\n\nBzorch\n\n});
38 ok scalar( grep { ref $_ and $_->can('type') } @t), 5
40 ok 0,1, "Wrong token count. Failing subsequent tests.\n";
41 for ( 1 .. 12 ) {ok 0}
43 ok $t[0]->type, 'start';
44 ok $t[1]->type, 'start';
45 ok $t[2]->type, 'text';
46 ok $t[3]->type, 'end';
47 ok $t[4]->type, 'end';
49 ok $t[0]->tagname, 'Document';
50 ok $t[1]->tagname, 'head1';
51 ok $t[2]->text, 'Things';
52 ok $t[3]->tagname, 'head1';
53 ok $t[4]->tagname, 'Document';
55 ok $t[0]->attr('start_line'), '5';
56 ok $t[1]->attr('start_line'), '5';
61 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63 qq{Woowoo\n\n=over\n\n=item *\n\nStuff L<HTML::TokeParser>\n\n}
64 . qq{=item *\n\nThings I<like that>\n\n=back\n\n=cut\n\n}
68 not( ok scalar( grep { ref $_ and $_->can('type') } @t) => 16 )
70 ok 0,1, "Wrong token count. Failing subsequent tests.\n";
71 for ( 1 .. 32 ) {ok 0}
73 ok $t[ 0]->type, 'start';
74 ok $t[ 1]->type, 'start';
75 ok $t[ 2]->type, 'start';
76 ok $t[ 3]->type, 'text';
77 ok $t[ 4]->type, 'start';
78 ok $t[ 5]->type, 'text';
79 ok $t[ 6]->type, 'end';
80 ok $t[ 7]->type, 'end';
82 ok $t[ 8]->type, 'start';
83 ok $t[ 9]->type, 'text';
84 ok $t[10]->type, 'start';
85 ok $t[11]->type, 'text';
86 ok $t[12]->type, 'end';
87 ok $t[13]->type, 'end';
88 ok $t[14]->type, 'end';
89 ok $t[15]->type, 'end';
93 ok $t[ 0]->tagname, 'Document';
94 ok $t[ 1]->tagname, 'over-bullet';
95 ok $t[ 2]->tagname, 'item-bullet';
96 ok $t[ 3]->text, 'Stuff ';
97 ok $t[ 4]->tagname, 'L';
98 ok $t[ 5]->text, 'HTML::TokeParser';
99 ok $t[ 6]->tagname, 'L';
100 ok $t[ 7]->tagname, 'item-bullet';
102 ok $t[ 8]->tagname, 'item-bullet';
103 ok $t[ 9]->text, 'Things ';
104 ok $t[10]->tagname, 'I';
105 ok $t[11]->text, 'like that';
106 ok $t[12]->tagname, 'I';
107 ok $t[13]->tagname, 'item-bullet';
108 ok $t[14]->tagname, 'over-bullet';
109 ok $t[15]->tagname, 'Document';
111 ok $t[4]->attr("type"), "pod";
115 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 print "# Testing unget_token\n";
119 my $p = Pod::Simple::PullParser->new;
120 $p->set_source( \qq{\nBzorch\n\n=pod\n\nLala\n\n\=cut\n} );
125 ok $t && $t->type, 'start';
126 ok $t && $t->tagname, 'Document';
127 print "# ungetting ($t).\n";
132 ok $t && $t->type, 'start';
133 ok $t && $t->tagname, 'Document';
137 ok $t && $t->type, 'start';
138 ok $t && $t->tagname, 'Para';
141 print "# ungetting (@to_save).\n";
142 $p->unget_token(@to_save);
147 ok $t && $t->type, 'start';
148 ok $t && $t->tagname, 'Document';
151 ok $t && $t->type, 'start';
152 ok $t && $t->tagname, 'Para';
159 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162 print "# Testing pullparsing from an arrayref\n";
163 my $p = Pod::Simple::PullParser->new;
165 $p->set_source( ['','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
168 while($t = $p->get_token) {
169 print "# Got a token: ", $t->dump, "\n#\n";
172 ok scalar(@t), 5; # count of tokens
173 ok $t[0]->type, 'start';
174 ok $t[1]->type, 'start';
175 ok $t[2]->type, 'text';
176 ok $t[3]->type, 'end';
177 ok $t[4]->type, 'end';
179 ok $t[0]->tagname, 'Document';
180 ok $t[1]->tagname, 'Para';
181 ok $t[2]->text, 'Lala zaza';
182 ok $t[3]->tagname, 'Para';
183 ok $t[4]->tagname, 'Document';
187 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190 print "# Testing pullparsing from an arrayref with terminal newlines\n";
191 my $p = Pod::Simple::PullParser->new;
193 $p->set_source( [ map "$_\n",
194 '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
197 while($t = $p->get_token) {
198 print "# Got a token: ", $t->dump, "\n#\n";
201 ok scalar(@t), 5; # count of tokens
202 ok $t[0]->type, 'start';
203 ok $t[1]->type, 'start';
204 ok $t[2]->type, 'text';
205 ok $t[3]->type, 'end';
206 ok $t[4]->type, 'end';
208 ok $t[0]->tagname, 'Document';
209 ok $t[1]->tagname, 'Para';
210 ok $t[2]->text, 'Lala zaza';
211 ok $t[3]->tagname, 'Para';
212 ok $t[4]->tagname, 'Document';
216 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218 END { unlink "temp.pod" }
220 print "# Testing pullparsing from a file\n";
221 my $p = Pod::Simple::PullParser->new;
223 open(OUT, ">temp.pod") || die "Can't write-open temp.pod: $!";
226 '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'
232 $p->set_source("temp.pod");
235 while($t = $p->get_token) {
236 print "# Got a token: ", $t->dump, "\n#\n";
238 print "# That's token number ", scalar(@t), "\n";
240 ok scalar(@t), 5; # count of tokens
241 ok $t[0]->type, 'start';
242 ok $t[1]->type, 'start';
243 ok $t[2]->type, 'text';
244 ok $t[3]->type, 'end';
245 ok $t[4]->type, 'end';
247 ok $t[0]->tagname, 'Document';
248 ok $t[1]->tagname, 'Para';
249 ok $t[2]->text, 'Lala zaza';
250 ok $t[3]->tagname, 'Para';
251 ok $t[4]->tagname, 'Document';
255 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
258 print "# Testing pullparsing from a glob\n";
259 my $p = Pod::Simple::PullParser->new;
261 open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
265 while($t = $p->get_token) {
266 print "# Got a token: ", $t->dump, "\n#\n";
268 print "# That's token number ", scalar(@t), "\n";
270 ok scalar(@t), 5; # count of tokens
271 ok $t[0]->type, 'start';
272 ok $t[1]->type, 'start';
273 ok $t[2]->type, 'text';
274 ok $t[3]->type, 'end';
275 ok $t[4]->type, 'end';
277 ok $t[0]->tagname, 'Document';
278 ok $t[1]->tagname, 'Para';
279 ok $t[2]->text, 'Lala zaza';
280 ok $t[3]->tagname, 'Para';
281 ok $t[4]->tagname, 'Document';
286 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
289 print "# Testing pullparsing from a globref\n";
290 my $p = Pod::Simple::PullParser->new;
292 open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
293 $p->set_source(\*IN);
296 while($t = $p->get_token) {
297 print "# Got a token: ", $t->dump, "\n#\n";
299 print "# That's token number ", scalar(@t), "\n";
301 ok scalar(@t), 5; # count of tokens
302 ok $t[0]->type, 'start';
303 ok $t[1]->type, 'start';
304 ok $t[2]->type, 'text';
305 ok $t[3]->type, 'end';
306 ok $t[4]->type, 'end';
308 ok $t[0]->tagname, 'Document';
309 ok $t[1]->tagname, 'Para';
310 ok $t[2]->text, 'Lala zaza';
311 ok $t[3]->tagname, 'Para';
312 ok $t[4]->tagname, 'Document';
317 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
320 print "# Testing pullparsing from a filehandle\n";
321 my $p = Pod::Simple::PullParser->new;
323 open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
324 $p->set_source(*IN{IO});
327 while($t = $p->get_token) {
328 print "# Got a token: ", $t->dump, "\n#\n";
330 print "# That's token number ", scalar(@t), "\n";
332 ok scalar(@t), 5; # count of tokens
333 ok $t[0]->type, 'start';
334 ok $t[1]->type, 'start';
335 ok $t[2]->type, 'text';
336 ok $t[3]->type, 'end';
337 ok $t[4]->type, 'end';
339 ok $t[0]->tagname, 'Document';
340 ok $t[1]->tagname, 'Para';
341 ok $t[2]->text, 'Lala zaza';
342 ok $t[3]->tagname, 'Para';
343 ok $t[4]->tagname, 'Document';
350 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353 print "# Wrapping up... one for the road...\n";
355 print "# --- Done with ", __FILE__, " --- \n";