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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
use strict;
use FileHandle::Unget;
use File::Spec::Functions qw(:ALL);
use Test::More tests => 7;
use File::Temp;
my $tmp = File::Temp->new();
{
print $tmp "first line\n";
print $tmp "second line\n";
print $tmp "third line\n";
close $tmp;
}
# Test normal semantics for input record separators
{
my $fh1 = new FileHandle::Unget($tmp->filename);
local $/ = "\n";
my $line1 = <$fh1>;
# 1
is($line1, "first line\n", 'First line');
local $/ = undef;
my $line2 = <$fh1>;
# 2
is($line2, "second line\nthird line\n", 'No eol separator');
$fh1->close;
}
# Test per-filehandle input record separator for 1 filehandle
{
my $fh1 = new FileHandle::Unget($tmp->filename);
local $/ = "\n";
my $line1 = <$fh1>;
# 3
is($line1, "first line\n", 'First line');
$fh1->input_record_separator("\n");
local $/ = undef;
my $line2 = <$fh1>;
# 4
is($line2, "second line\n", 'Second line');
$fh1->ungets($line2);
$fh1->clear_input_record_separator();
my $line3 = <$fh1>;
#5
is($line3, "second line\nthird line\n", 'Newline end of file');
$fh1->close;
}
# Test per-filehandle input record separator for 2 filehandles
{
my $fh1 = new FileHandle::Unget($tmp->filename);
my $fh2 = new FileHandle::Unget($tmp->filename);
local $/ = ' ';
$fh1->input_record_separator("\n");
$fh2->input_record_separator(undef);
my $line1 = <$fh1>;
my $line2 = <$fh2>;
# 6
is($line1, "first line\n", 'First line');
# 7
is($line2, "first line\nsecond line\nthird line\n", 'Undef end of line');
$fh1->close;
$fh2->close;
}
|