03_longfetch.t revision 1.1.1.3
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 11use strict; 12use warnings; 13 14my $file = "tf03-$$.txt"; 15$: = Tie::File::_default_recsep(); 16my $data = "rec0$:rec1$:rec2$:"; 17 18print "1..8\n"; 19 20my $N = 1; 21use Tie::File; 22print "ok $N\n"; $N++; 23 24open F, '>', $file or die $!; 25binmode F; 26print F $data; 27close F; 28 29my @a; 30my $o = tie @a, 'Tie::File', $file, autochomp => 0; 31print $o ? "ok $N\n" : "not ok $N\n"; 32$N++; 33 34$: = $o->{recsep}; 35 36my $n; 37 38# 3-5 39for (2, 1, 0) { 40 my $rec = $a[$_]; 41 print $rec eq "rec$_$:" ? "ok $N\n" : "not ok $N # rec=<$rec> ?\n"; 42 $N++; 43} 44 45# 6-8 46for (3, 4, 6) { 47 my $rec = $a[$_]; 48 print ((not defined $rec) ? "ok $N\n" : "not ok $N # rec=<$rec> is defined\n"); 49 $N++; 50} 51 52END { 53 undef $o; 54 untie @a; 55 1 while unlink $file; 56} 57 58