File: eof.t

package info (click to toggle)
libfilehandle-unget-perl 0.1634-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 2,160; makefile: 2
file content (50 lines) | stat: -rwxr-xr-x 779 bytes parent folder | download | duplicates (5)
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
use strict;
use FileHandle::Unget;
use File::Spec::Functions qw(:ALL);
use Test::More tests => 4;
use File::Temp;

my $tmp = File::Temp->new();

{
  print $tmp "first line\n";
  print $tmp "second line\n";
  close $tmp;
}

# Test getline on the end of the file
{
  my $fh = new FileHandle::Unget($tmp->filename);

  my $line;
  
  $line = <$fh>;
  # 1
  is($line,"first line\n",'Read first line');

  $line = <$fh>;
  # 2
  is($line,"second line\n",'Read second line');

  $line = <$fh>;
  # 3
  is($line,undef,'EOF getline');

  $fh->close;
}

# Test getlines on the end of the file
{
  my $fh = new FileHandle::Unget($tmp->filename);

  my $line;
  
  $line = <$fh>;
  $line = <$fh>;

  my @lines = $fh->getlines();
  # 4
  is($lines[0],undef,'EOF getlines');

  $fh->close;
}