4
BEGIN { plan tests => 136 };
6
#use Pod::Simple::Debug (5);
8
#sub Pod::Simple::MANY_LINES () {1}
9
#sub Pod::Simple::PullParser::DEBUG () {1}
12
use Pod::Simple::PullParser;
15
my $p = Pod::Simple::PullParser->new;
16
$p->set_source( \( $_[0] ) );
18
while($t = $p->get_token) { push @t, $t }
19
print "# Count of tokens: ", scalar(@t), "\n";
20
print "# I.e., {", join("\n# + ",
21
map ref($_) . ": " . $_->dump, @t), "} \n";
27
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
@t = pump_it_up(qq{\n\nProk\n\n=head1 Things\n\n=cut\n\nBzorch\n\n});
32
ok scalar( grep { ref $_ and $_->can('type') } @t), 5
34
ok 0,1, "Wrong token count. Failing subsequent tests.\n";
35
for ( 1 .. 12 ) {ok 0}
37
ok $t[0]->type, 'start';
38
ok $t[1]->type, 'start';
39
ok $t[2]->type, 'text';
40
ok $t[3]->type, 'end';
41
ok $t[4]->type, 'end';
43
ok $t[0]->tagname, 'Document';
44
ok $t[1]->tagname, 'head1';
45
ok $t[2]->text, 'Things';
46
ok $t[3]->tagname, 'head1';
47
ok $t[4]->tagname, 'Document';
49
ok $t[0]->attr('start_line'), '5';
50
ok $t[1]->attr('start_line'), '5';
55
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
qq{Woowoo\n\n=over\n\n=item *\n\nStuff L<HTML::TokeParser>\n\n}
58
. qq{=item *\n\nThings I<like that>\n\n=back\n\n=cut\n\n}
62
not( ok scalar( grep { ref $_ and $_->can('type') } @t) => 16 )
64
ok 0,1, "Wrong token count. Failing subsequent tests.\n";
65
for ( 1 .. 32 ) {ok 0}
67
ok $t[ 0]->type, 'start';
68
ok $t[ 1]->type, 'start';
69
ok $t[ 2]->type, 'start';
70
ok $t[ 3]->type, 'text';
71
ok $t[ 4]->type, 'start';
72
ok $t[ 5]->type, 'text';
73
ok $t[ 6]->type, 'end';
74
ok $t[ 7]->type, 'end';
76
ok $t[ 8]->type, 'start';
77
ok $t[ 9]->type, 'text';
78
ok $t[10]->type, 'start';
79
ok $t[11]->type, 'text';
80
ok $t[12]->type, 'end';
81
ok $t[13]->type, 'end';
82
ok $t[14]->type, 'end';
83
ok $t[15]->type, 'end';
87
ok $t[ 0]->tagname, 'Document';
88
ok $t[ 1]->tagname, 'over-bullet';
89
ok $t[ 2]->tagname, 'item-bullet';
90
ok $t[ 3]->text, 'Stuff ';
91
ok $t[ 4]->tagname, 'L';
92
ok $t[ 5]->text, 'HTML::TokeParser';
93
ok $t[ 6]->tagname, 'L';
94
ok $t[ 7]->tagname, 'item-bullet';
96
ok $t[ 8]->tagname, 'item-bullet';
97
ok $t[ 9]->text, 'Things ';
98
ok $t[10]->tagname, 'I';
99
ok $t[11]->text, 'like that';
100
ok $t[12]->tagname, 'I';
101
ok $t[13]->tagname, 'item-bullet';
102
ok $t[14]->tagname, 'over-bullet';
103
ok $t[15]->tagname, 'Document';
105
ok $t[4]->attr("type"), "pod";
109
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
print "# Testing unget_token\n";
113
my $p = Pod::Simple::PullParser->new;
114
$p->set_source( \qq{\nBzorch\n\n=pod\n\nLala\n\n\=cut\n} );
119
ok $t && $t->type, 'start';
120
ok $t && $t->tagname, 'Document';
121
print "# ungetting ($t).\n";
126
ok $t && $t->type, 'start';
127
ok $t && $t->tagname, 'Document';
131
ok $t && $t->type, 'start';
132
ok $t && $t->tagname, 'Para';
135
print "# ungetting (@to_save).\n";
136
$p->unget_token(@to_save);
141
ok $t && $t->type, 'start';
142
ok $t && $t->tagname, 'Document';
145
ok $t && $t->type, 'start';
146
ok $t && $t->tagname, 'Para';
153
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156
print "# Testing pullparsing from an arrayref\n";
157
my $p = Pod::Simple::PullParser->new;
159
$p->set_source( ['','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
162
while($t = $p->get_token) {
163
print "# Got a token: ", $t->dump, "\n#\n";
166
ok scalar(@t), 5; # count of tokens
167
ok $t[0]->type, 'start';
168
ok $t[1]->type, 'start';
169
ok $t[2]->type, 'text';
170
ok $t[3]->type, 'end';
171
ok $t[4]->type, 'end';
173
ok $t[0]->tagname, 'Document';
174
ok $t[1]->tagname, 'Para';
175
ok $t[2]->text, 'Lala zaza';
176
ok $t[3]->tagname, 'Para';
177
ok $t[4]->tagname, 'Document';
181
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184
print "# Testing pullparsing from an arrayref with terminal newlines\n";
185
my $p = Pod::Simple::PullParser->new;
187
$p->set_source( [ map "$_\n",
188
'','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
191
while($t = $p->get_token) {
192
print "# Got a token: ", $t->dump, "\n#\n";
195
ok scalar(@t), 5; # count of tokens
196
ok $t[0]->type, 'start';
197
ok $t[1]->type, 'start';
198
ok $t[2]->type, 'text';
199
ok $t[3]->type, 'end';
200
ok $t[4]->type, 'end';
202
ok $t[0]->tagname, 'Document';
203
ok $t[1]->tagname, 'Para';
204
ok $t[2]->text, 'Lala zaza';
205
ok $t[3]->tagname, 'Para';
206
ok $t[4]->tagname, 'Document';
210
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212
END { unlink "temp.pod" }
214
print "# Testing pullparsing from a file\n";
215
my $p = Pod::Simple::PullParser->new;
217
open(OUT, ">temp.pod") || die "Can't write-open temp.pod: $!";
220
'','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'
226
$p->set_source("temp.pod");
229
while($t = $p->get_token) {
230
print "# Got a token: ", $t->dump, "\n#\n";
232
print "# That's token number ", scalar(@t), "\n";
234
ok scalar(@t), 5; # count of tokens
235
ok $t[0]->type, 'start';
236
ok $t[1]->type, 'start';
237
ok $t[2]->type, 'text';
238
ok $t[3]->type, 'end';
239
ok $t[4]->type, 'end';
241
ok $t[0]->tagname, 'Document';
242
ok $t[1]->tagname, 'Para';
243
ok $t[2]->text, 'Lala zaza';
244
ok $t[3]->tagname, 'Para';
245
ok $t[4]->tagname, 'Document';
249
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
252
print "# Testing pullparsing from a glob\n";
253
my $p = Pod::Simple::PullParser->new;
255
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
259
while($t = $p->get_token) {
260
print "# Got a token: ", $t->dump, "\n#\n";
262
print "# That's token number ", scalar(@t), "\n";
264
ok scalar(@t), 5; # count of tokens
265
ok $t[0]->type, 'start';
266
ok $t[1]->type, 'start';
267
ok $t[2]->type, 'text';
268
ok $t[3]->type, 'end';
269
ok $t[4]->type, 'end';
271
ok $t[0]->tagname, 'Document';
272
ok $t[1]->tagname, 'Para';
273
ok $t[2]->text, 'Lala zaza';
274
ok $t[3]->tagname, 'Para';
275
ok $t[4]->tagname, 'Document';
280
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
283
print "# Testing pullparsing from a globref\n";
284
my $p = Pod::Simple::PullParser->new;
286
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
287
$p->set_source(\*IN);
290
while($t = $p->get_token) {
291
print "# Got a token: ", $t->dump, "\n#\n";
293
print "# That's token number ", scalar(@t), "\n";
295
ok scalar(@t), 5; # count of tokens
296
ok $t[0]->type, 'start';
297
ok $t[1]->type, 'start';
298
ok $t[2]->type, 'text';
299
ok $t[3]->type, 'end';
300
ok $t[4]->type, 'end';
302
ok $t[0]->tagname, 'Document';
303
ok $t[1]->tagname, 'Para';
304
ok $t[2]->text, 'Lala zaza';
305
ok $t[3]->tagname, 'Para';
306
ok $t[4]->tagname, 'Document';
311
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
314
print "# Testing pullparsing from a filehandle\n";
315
my $p = Pod::Simple::PullParser->new;
317
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
318
$p->set_source(*IN{IO});
321
while($t = $p->get_token) {
322
print "# Got a token: ", $t->dump, "\n#\n";
324
print "# That's token number ", scalar(@t), "\n";
326
ok scalar(@t), 5; # count of tokens
327
ok $t[0]->type, 'start';
328
ok $t[1]->type, 'start';
329
ok $t[2]->type, 'text';
330
ok $t[3]->type, 'end';
331
ok $t[4]->type, 'end';
333
ok $t[0]->tagname, 'Document';
334
ok $t[1]->tagname, 'Para';
335
ok $t[2]->text, 'Lala zaza';
336
ok $t[3]->tagname, 'Para';
337
ok $t[4]->tagname, 'Document';
344
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347
print "# Wrapping up... one for the road...\n";
349
print "# --- Done with ", __FILE__, " --- \n";