$extra = 1
if $st ;
- plan(tests => 615 + $extra) ;
+ plan(tests => 639 + $extra) ;
}
sub myGZreadFile
my $lex = new LexFile my $name ;
+ #my $name = "/tmp/try.lzf";
my $hello = <<EOM ;
hello world
}
{
+ # embed a compressed file in another buffer
+ #================================
+
+
+ my $hello = <<EOM ;
+hello world
+this is a test
+EOM
+
+ my $trailer = "trailer data" ;
+
+ my $compressed ;
+
+ {
+ ok my $x = new $CompressClass(\$compressed);
+
+ ok $x->write($hello) ;
+ ok $x->close ;
+ $compressed .= $trailer ;
+ }
+
+ my $uncomp;
+ ok my $x = new $UncompressClass(\$compressed, Append => 1) ;
+ 1 while $x->read($uncomp) > 0 ;
+
+ ok $uncomp eq $hello ;
+ is $x->trailingData(), $trailer ;
+
+ }
+
+ {
# Write
# these tests come almost 100% from IO::String
is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
("1234567890" x 3) . "67890\n" .
- "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
+ "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n",
+ "myGZreadFile ok";
}
is $., 0;
is $io->input_line_number, 0;
- ok ! $io->eof;
- is $io->tell(), 0 ;
+ ok ! $io->eof, "eof";
+ is $io->tell(), 0, "tell 0" ;
#my @lines = <$io>;
my @lines = $io->getlines();
is @lines, 6
}
{
+ # Record mode
+ my $reclen = 7 ;
+ my $expected_records = int(length($str) / $reclen)
+ + (length($str) % $reclen ? 1 : 0);
+ local $/ = \$reclen;
+
+ my $io = $UncompressClass->new($name);
+ is $., 0;
+ is $io->input_line_number, 0;
+
+ ok ! $io->eof;
+ my @lines = $io->getlines();
+ is $., $expected_records;
+ is $io->input_line_number, $expected_records;
+ ok $io->eof;
+ is @lines, $expected_records,
+ "Got $expected_records records\n" ;
+ ok $lines[0] eq substr($str, 0, $reclen)
+ or print "# $lines[0]\n";
+ ok $lines[1] eq substr($str, $reclen, $reclen);
+ }
+
+ {
local $/ = "is";
my $io = $UncompressClass->new($name);
my @lines = ();
is $io->read($buf, 0), 0, "Requested 0 bytes" ;
- ok $io->read($buf, 3) == 3 ;
- ok $buf eq "Thi";
+ is $io->read($buf, 3), 3 ;
+ is $buf, "Thi";
- ok $io->sysread($buf, 3, 2) == 3 ;
- ok $buf eq "Ths i"
+ is $io->sysread($buf, 3, 2), 3 ;
+ is $buf, "Ths i"
or print "# [$buf]\n" ;;
ok ! $io->eof;
}
{
+ # Record mode
+ my $reclen = 7 ;
+ my $expected_records = int(length($str) / $reclen)
+ + (length($str) % $reclen ? 1 : 0);
+ local $/ = \$reclen;
+
+ my $io = $UncompressClass->new($name);
+ is $., 0;
+ is $io->input_line_number, 0;
+
+ ok ! $io->eof;
+ my @lines = $io->getlines();
+ is $., $expected_records;
+ is $io->input_line_number, $expected_records;
+ ok $io->eof;
+ is @lines, $expected_records,
+ "Got $expected_records records\n" ;
+ ok $lines[0] eq substr($str, 0, $reclen)
+ or print "# $lines[0]\n";
+ ok $lines[1] eq substr($str, $reclen, $reclen);
+ }
+
+ {
local $/ = "is";
my $io = $UncompressClass->new($name);
my @lines = ();