IO-Stringy
view release on metacpan or search on metacpan
t/IO_Scalar.t view on Meta::CPAN
is($buff, 'one too', 'seek(-7,1) - read(): got correct value');
}
# tie
{
my $th = geniosym;
tie(*{$th}, 'IO::Scalar');
ok($th, 'tie: got tied handle');
print {$th} @orig;
tied(*{$th})->seek(0, 0);
my @lines;
while (my $line = <$th>) {
push @lines, $line;
}
is(join('', @lines), join('', @orig), 'tied seek readline: got correct value');
@lines = ();
tied(*{$th})->seek(0, 0);
@lines = <$th>;
is(join('', @lines), join('', @orig), 'tied seek readlines: got correct value');
}
# record seps
{
my @lines = (
"par 1, line 1\n",
"par 1, line 2\n",
"\n",
"\n",
"\n",
"\n",
"par 2, line 1\n",
"\n",
"par 3, line 1\n",
"par 3, line 2\n",
"par 3, line 3",
);
my $all = join('', @lines);
# Slurp everything
{
my $ios = IO::Scalar->new(\$all);
local $/ = undef;
is($ios->getline, $all, "recordsep: undef - getline");
}
# Read a little, slurp the rest
{
my $ios = IO::Scalar->new(\$all);
is($ios->getline, $lines[0], "recordsep: undef - get first line");
local $/ = undef;
is($ios->getline, join('', @lines[1..$#lines]), "recordsep: undef - slurp the rest");
}
# Read paragraph by paragraph
{
my $ios = IO::Scalar->new(\$all);
local $/ = "";
is($ios->getline, join('', @lines[0..2]), "recordsep: empty - first par");
is($ios->getline, join('', @lines[6..7]), "recordsep: empty - second par");
is($ios->getline, join('', @lines[8..10]), "recordsep empty - third par");
}
# Read record by record
{
my $ios = IO::Scalar->new(\$all);
local $/ = "1,";
is($ios->getline, "par 1,", "recordsep: custom - first rec");
is($ios->getline, " line 1\npar 1,", "recordsep: custom - second rec");
}
# Read line by line
{
my $ios = IO::Scalar->new(\$all);
local $/ = "\n";
for my $i (0..10) {
is($ios->getline, $lines[$i], "recordsep: newline - rec $i");
}
}
}
( run in 0.872 second using v1.01-cache-2.11-cpan-8dfa8b56332 )