IO-stringy
view release on metacpan or search on metacpan
t/Common.pm view on Meta::CPAN
# Gotl => $tell_tie);
}
#------------------------------
# test_recordsep
#------------------------------
# Try $/ tests.
#
# 3 x undef
# 3 x empty
# 2 x custom
# 11 x newline
#
sub test_recordsep_count {
my ($self, $seps) = @_;
my $count = 0;
$count += 3 if ($seps =~ /undef/) ;
$count += 3 if ($seps =~ /empty/) ;
$count += 2 if ($seps =~ /custom/) ;
$count += 11 if ($seps =~ /newline/);
$count;
}
sub test_recordsep {
my ($self, $seps, $opener) = @_;
my $GH;
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:
if ($seps =~ /undef/) {
$GH = &$opener(\@lines);
local $/ = undef;
$T->ok_eq($GH->getline, $all,
"RECORDSEP undef: getline slurps everything");
}
### Read a little, slurp the rest:
if ($seps =~ /undef/) {
$GH = &$opener(\@lines);
$T->ok_eq($GH->getline, $lines[0],
"RECORDSEP undef: get first line");
local $/ = undef;
$T->ok_eq($GH->getline, join('', @lines[1..$#lines]),
"RECORDSEP undef: slurp the rest");
}
### Read paragraph by paragraph:
if ($seps =~ /empty/) {
$GH = &$opener(\@lines);
local $/ = "";
$T->ok_eq($GH->getline, join('', @lines[0..2]),
"RECORDSEP empty: first par");
$T->ok_eq($GH->getline, join('', @lines[6..7]),
"RECORDSEP empty: second par");
$T->ok_eq($GH->getline, join('', @lines[8..10]),
"RECORDSEP empty: third par");
}
### Read record by record:
if ($seps =~ /custom/) {
$GH = &$opener(\@lines);
local $/ = "1,";
$T->ok_eq($GH->getline, "par 1,",
"RECORDSEP custom: first rec");
$T->ok_eq($GH->getline, " line 1\npar 1,",
"RECORDSEP custom: second rec");
}
### Read line by line:
if ($seps =~ /newline/) {
$GH = &$opener(\@lines);
local $/ = "\n";
for my $i (0..10) {
$T->ok_eq($GH->getline, $lines[$i],
"RECORDSEP newline: rec $i");
}
}
}
#------------------------------
1;
( run in 2.279 seconds using v1.01-cache-2.11-cpan-364913b4093 )