1#!/usr/bin/perl
2#
3# Make sure we can fetch a record in the middle of the file
4# before we've ever looked at any records before it
5#
6# Make sure fetching past the end of the file returns the undefined value
7#
8# (tests _fill_offsets_to() )
9#
10
11my $file = "tf03-$$.txt";
12$: = Tie::File::_default_recsep();
13my $data = "rec0$:rec1$:rec2$:";
14
15print "1..8\n";
16
17my $N = 1;
18use Tie::File;
19print "ok $N\n"; $N++;
20
21open F, '>', $file or die $!;
22binmode F;
23print F $data;
24close F;
25
26
27my $o = tie @a, 'Tie::File', $file, autochomp => 0;
28print $o ? "ok $N\n" : "not ok $N\n";
29$N++;
30
31$: = $o->{recsep};
32
33my $n;
34
35# 3-5
36for (2, 1, 0) {
37  my $rec = $a[$_];
38  print $rec eq "rec$_$:" ? "ok $N\n" : "not ok $N # rec=<$rec> ?\n";
39  $N++;
40}
41
42# 6-8
43for (3, 4, 6) {
44  my $rec = $a[$_];
45  print ((not defined $rec) ? "ok $N\n" : "not ok $N # rec=<$rec> is defined\n");
46  $N++;
47}
48
49END {
50  undef $o;
51  untie @a;
52  1 while unlink $file;
53}
54
55