~ubuntu-branches/ubuntu/intrepid/horae/intrepid

« back to all changes in this revision

Viewing changes to 0CPAN/Pod-Simple-3.03/t/puller.t

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
use strict;
3
 
use Test;
4
 
BEGIN { plan tests => 136 };
5
 
 
6
 
#use Pod::Simple::Debug (5);
7
 
 
8
 
#sub Pod::Simple::MANY_LINES () {1}
9
 
#sub Pod::Simple::PullParser::DEBUG () {1}
10
 
 
11
 
 
12
 
use Pod::Simple::PullParser;
13
 
 
14
 
sub pump_it_up {
15
 
  my $p = Pod::Simple::PullParser->new;
16
 
  $p->set_source( \( $_[0] ) );
17
 
  my(@t, $t);
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";
22
 
  return @t;
23
 
}
24
 
 
25
 
my @t;
26
 
 
27
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
 
 
29
 
@t = pump_it_up(qq{\n\nProk\n\n=head1 Things\n\n=cut\n\nBzorch\n\n});
30
 
 
31
 
if(not(
32
 
  ok scalar( grep { ref $_ and $_->can('type') } @t), 5
33
 
)) {
34
 
  ok 0,1, "Wrong token count. Failing subsequent tests.\n";
35
 
  for ( 1 .. 12 ) {ok 0}
36
 
} else {
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';
42
 
 
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';
48
 
 
49
 
  ok $t[0]->attr('start_line'), '5';
50
 
  ok $t[1]->attr('start_line'), '5';
51
 
}
52
 
 
53
 
 
54
 
 
55
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
 
@t = pump_it_up(
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}
59
 
);
60
 
 
61
 
if(
62
 
  not( ok scalar( grep { ref $_ and $_->can('type') } @t) => 16 )
63
 
) {
64
 
  ok 0,1, "Wrong token count. Failing subsequent tests.\n";
65
 
  for ( 1 .. 32 ) {ok 0}
66
 
} else {
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';
75
 
 
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';
84
 
 
85
 
 
86
 
 
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';
95
 
 
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';
104
 
 
105
 
  ok $t[4]->attr("type"), "pod";
106
 
}
107
 
 
108
 
 
109
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110
 
{
111
 
print "# Testing unget_token\n";
112
 
 
113
 
my $p = Pod::Simple::PullParser->new;
114
 
$p->set_source( \qq{\nBzorch\n\n=pod\n\nLala\n\n\=cut\n} );
115
 
 
116
 
ok 1;
117
 
my $t;
118
 
$t = $p->get_token;
119
 
ok $t && $t->type, 'start';
120
 
ok $t && $t->tagname, 'Document';
121
 
print "# ungetting ($t).\n";
122
 
$p->unget_token($t);
123
 
ok 1;
124
 
 
125
 
$t = $p->get_token;
126
 
ok $t && $t->type, 'start';
127
 
ok $t && $t->tagname, 'Document';
128
 
my @to_save = ($t);
129
 
 
130
 
$t = $p->get_token;
131
 
ok $t && $t->type, 'start';
132
 
ok $t && $t->tagname, 'Para';
133
 
push @to_save, $t;
134
 
 
135
 
print "# ungetting (@to_save).\n";
136
 
$p->unget_token(@to_save);
137
 
splice @to_save;
138
 
 
139
 
 
140
 
$t = $p->get_token;
141
 
ok $t && $t->type, 'start';
142
 
ok $t && $t->tagname, 'Document';
143
 
 
144
 
$t = $p->get_token;
145
 
ok $t && $t->type, 'start';
146
 
ok $t && $t->tagname, 'Para';
147
 
 
148
 
ok 1;
149
 
 
150
 
}
151
 
 
152
 
 
153
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
 
 
155
 
{
156
 
print "# Testing pullparsing from an arrayref\n";
157
 
my $p = Pod::Simple::PullParser->new;
158
 
ok 1;
159
 
$p->set_source( ['','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
160
 
ok 1;
161
 
my( @t, $t );
162
 
while($t = $p->get_token) {
163
 
  print "# Got a token: ", $t->dump, "\n#\n";
164
 
  push @t, $t;
165
 
}
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';
172
 
 
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';
178
 
 
179
 
}
180
 
 
181
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
 
 
183
 
{
184
 
print "# Testing pullparsing from an arrayref with terminal newlines\n";
185
 
my $p = Pod::Simple::PullParser->new;
186
 
ok 1;
187
 
$p->set_source( [ map "$_\n",
188
 
  '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'] );
189
 
ok 1;
190
 
my( @t, $t );
191
 
while($t = $p->get_token) {
192
 
  print "# Got a token: ", $t->dump, "\n#\n";
193
 
  push @t, $t;
194
 
}
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';
201
 
 
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';
207
 
 
208
 
}
209
 
 
210
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211
 
 
212
 
END { unlink "temp.pod" }
213
 
{
214
 
print "# Testing pullparsing from a file\n";
215
 
my $p = Pod::Simple::PullParser->new;
216
 
ok 1;
217
 
open(OUT, ">temp.pod") || die "Can't write-open temp.pod: $!";
218
 
print OUT
219
 
 map "$_\n",
220
 
  '','Bzorch', '','=pod', '', 'Lala', 'zaza', '', '=cut'
221
 
;
222
 
close(OUT);
223
 
ok 1;
224
 
sleep 1;
225
 
 
226
 
$p->set_source("temp.pod");
227
 
 
228
 
my( @t, $t );
229
 
while($t = $p->get_token) {
230
 
  print "# Got a token: ", $t->dump, "\n#\n";
231
 
  push @t, $t;
232
 
  print "#  That's token number ", scalar(@t), "\n";
233
 
}
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';
240
 
 
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';
246
 
 
247
 
}
248
 
 
249
 
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
250
 
 
251
 
{
252
 
print "# Testing pullparsing from a glob\n";
253
 
my $p = Pod::Simple::PullParser->new;
254
 
ok 1;
255
 
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
256
 
$p->set_source(*IN);
257
 
 
258
 
my( @t, $t );
259
 
while($t = $p->get_token) {
260
 
  print "# Got a token: ", $t->dump, "\n#\n";
261
 
  push @t, $t;
262
 
  print "#  That's token number ", scalar(@t), "\n";
263
 
}
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';
270
 
 
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';
276
 
close(IN);
277
 
 
278
 
}
279
 
 
280
 
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
281
 
 
282
 
{
283
 
print "# Testing pullparsing from a globref\n";
284
 
my $p = Pod::Simple::PullParser->new;
285
 
ok 1;
286
 
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
287
 
$p->set_source(\*IN);
288
 
 
289
 
my( @t, $t );
290
 
while($t = $p->get_token) {
291
 
  print "# Got a token: ", $t->dump, "\n#\n";
292
 
  push @t, $t;
293
 
  print "#  That's token number ", scalar(@t), "\n";
294
 
}
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';
301
 
 
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';
307
 
close(IN);
308
 
 
309
 
}
310
 
 
311
 
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
312
 
 
313
 
{
314
 
print "# Testing pullparsing from a filehandle\n";
315
 
my $p = Pod::Simple::PullParser->new;
316
 
ok 1;
317
 
open(IN, "<temp.pod") || die "Can't read-open temp.pod: $!";
318
 
$p->set_source(*IN{IO});
319
 
 
320
 
my( @t, $t );
321
 
while($t = $p->get_token) {
322
 
  print "# Got a token: ", $t->dump, "\n#\n";
323
 
  push @t, $t;
324
 
  print "#  That's token number ", scalar(@t), "\n";
325
 
}
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';
332
 
 
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';
338
 
close(IN);
339
 
 
340
 
}
341
 
 
342
 
 
343
 
 
344
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345
 
 
346
 
 
347
 
print "# Wrapping up... one for the road...\n";
348
 
ok 1;
349
 
print "# --- Done with ", __FILE__, " --- \n";
350
 
 
351
 
__END__
352