File: stream.t

package info (click to toggle)
libxml-parser-perl 2.47-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: xml: 3,937; perl: 2,026; makefile: 38; ansic: 27
file content (53 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
BEGIN { print "1..3\n"; }
END { print "not ok 1\n" unless $loaded; }
use XML::Parser;
$loaded = 1;
print "ok 1\n";

my $delim   = '------------123453As23lkjlklz877';
my $file    = 'samples/REC-xml-19980210.xml';
my $tmpfile = 'stream.tmp';

my $cnt = 0;

open( my $out_fh, '>', $tmpfile ) or die "Couldn't open $tmpfile for output";
open( my $in_fh,  '<', $file )    or die "Couldn't open $file for input";

while (<$in_fh>) {
    print $out_fh $_;
}

close($in_fh);
print $out_fh "$delim\n";

open( $in_fh, $file );
while (<$in_fh>) {
    print $out_fh $_;
}

close($in_fh);
close($out_fh);

my $parser = new XML::Parser(
    Stream_Delimiter => $delim,
    Handlers         => {
        Comment => sub { $cnt++; }
    }
);

open( my $fh, $tmpfile );

$parser->parse($fh);

print "not " if ( $cnt != 37 );
print "ok 2\n";

$cnt = 0;

$parser->parse($fh);

print "not " if ( $cnt != 37 );
print "ok 3\n";

close($fh);
unlink($tmpfile);