File: tell.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 (49 lines) | stat: -rwxr-xr-x 737 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
use strict;
use FileHandle::Unget;
use File::Spec::Functions qw(:ALL);
use Test::More tests => 5;
use File::Temp;

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

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

# Test tell($fh) and scalar line reading
{
  my $fh = new FileHandle::Unget($tmp->filename);

  my $line = <$fh>;
  # 1
  is(tell($fh),11,'Tell 1');

  $line = <$fh>;
  # 2
  is(tell($fh),23,'Tell 2');

  $fh->close;
}

# Test tell($fh) and ungets
{
  my $fh = new FileHandle::Unget($tmp->filename);

  my $line = <$fh>;
  # 3
  is(tell($fh),11,'Tell 3');

  $fh->ungets('12345');
  # 4
  is(tell($fh),6,'Tell 4');

  $fh->ungets('1234567890');
  # 5
  is(tell($fh),-4,'Tell 5');

  $fh->close;
}