This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Alphabetise AUTHORS
[perl5.git] / dist / Tie-File / t / 03_longfetch.t
CommitLineData
b5aed31e
AMS
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#
0b28bc9a
AMS
6# Make sure fetching past the end of the file returns the undefined value
7#
b5aed31e
AMS
8# (tests _fill_offsets_to() )
9#
10
11my $file = "tf$$.txt";
b3fe5a4c
AMS
12$: = Tie::File::_default_recsep();
13my $data = "rec0$:rec1$:rec2$:";
b5aed31e 14
0b28bc9a 15print "1..8\n";
b5aed31e
AMS
16
17my $N = 1;
18use Tie::File;
19print "ok $N\n"; $N++;
20
21open F, "> $file" or die $!;
1768807e 22binmode F;
b5aed31e
AMS
23print F $data;
24close F;
25
26
0b28bc9a 27my $o = tie @a, 'Tie::File', $file, autochomp => 0;
b5aed31e
AMS
28print $o ? "ok $N\n" : "not ok $N\n";
29$N++;
30
b3fe5a4c
AMS
31$: = $o->{recsep};
32
b5aed31e
AMS
33my $n;
34
35# 3-5
36for (2, 1, 0) {
0b28bc9a
AMS
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");
b5aed31e
AMS
46 $N++;
47}
48
49END {
7b6b3db1
JH
50 undef $o;
51 untie @a;
b5aed31e
AMS
52 1 while unlink $file;
53}
54