diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
commit | 2f253cfc85ffd55a8acb988e91f0bc5ab348124c (patch) | |
tree | 4734ccd522c71dd455879162006742002f8c1565 /t/parsefile.t | |
download | HTML-Parser-tarball-master.tar.gz |
HTML-Parser-3.71HEADHTML-Parser-3.71master
Diffstat (limited to 't/parsefile.t')
-rw-r--r-- | t/parsefile.t | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/t/parsefile.t b/t/parsefile.t new file mode 100644 index 0000000..f373f06 --- /dev/null +++ b/t/parsefile.t @@ -0,0 +1,45 @@ +use Test::More tests => 6; + +my $filename = "file$$.htm"; +die "$filename is already there" if -e $filename; +open(FILE, ">$filename") || die "Can't create $filename: $!"; +print FILE <<'EOT'; close(FILE); +<title>Heisan</title> +EOT + +{ + package MyParser; + require HTML::Parser; + @ISA=qw(HTML::Parser); + + sub start + { + my($self, $tag, $attr) = @_; + Test::More::is($tag, "title"); + } +} + +MyParser->new->parse_file($filename); +open(FILE, $filename) || die; +MyParser->new->parse_file(*FILE); +seek(FILE, 0, 0) || die; +MyParser->new->parse_file(\*FILE); +close(FILE); + +require IO::File; +my $io = IO::File->new($filename) || die; +MyParser->new->parse_file($io); +$io->seek(0, 0) || die; +MyParser->new->parse_file(*$io); + +my $text = ''; +$io->seek(0, 0) || die; +MyParser->new( + start_h => [ sub{ shift->eof; }, "self" ], + text_h => [ sub{ $text = shift; }, "text" ])->parse_file(*$io); +ok(!$text); + +close($io); # needed because of bug in perl +undef($io); + +unlink($filename) or warn "Can't unlink $filename: $!"; |