File: multiple_handles.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 (45 lines) | stat: -rwxr-xr-x 769 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
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 ungets'ing and reading a line of data
{
  my $fh1 = new FileHandle::Unget($tmp->filename);
  my $fh2 = new FileHandle::Unget($tmp->filename);

  my $line = <$fh1>;
  $line = <$fh2>;

  $fh1->ungets("inserted 1\n");
  $fh2->ungets("inserted 2\n");

  $line = <$fh1>;
  # 1
  is($line, "inserted 1\n", 'Unget 1');

  $line = <$fh2>;
  # 2
  is($line, "inserted 2\n", 'Unget 2');

  $line = <$fh1>;
  # 3
  is($line, "second line\n", 'Get 1');

  $line = <$fh2>;
  # 4
  is($line, "second line\n", 'Get 2');

  $fh1->close;
  $fh2->close;
}