[perl #32717] BeOS specific Updates
[p5sagit/p5-mst-13.2.git] / lib / Tie / File / t / 03_longfetch.t
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
11 my $file = "tf$$.txt";
12 $: = Tie::File::_default_recsep();
13 my $data = "rec0$:rec1$:rec2$:";
14
15 print "1..8\n";
16
17 my $N = 1;
18 use Tie::File;
19 print "ok $N\n"; $N++;
20
21 open F, "> $file" or die $!;
22 binmode F;
23 print F $data;
24 close F;
25
26
27 my $o = tie @a, 'Tie::File', $file, autochomp => 0;
28 print $o ? "ok $N\n" : "not ok $N\n";
29 $N++;
30
31 $: = $o->{recsep};
32
33 my $n;
34
35 # 3-5
36 for (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
43 for (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
49 END {
50   undef $o;
51   untie @a;
52   1 while unlink $file;
53 }
54