1#!/usr/bin/perl
2
3# 2003-04-09 Tels: test the offset method from 0.94
4
5use Test::More;
6use strict;
7use File::Spec;
8
9use POSIX 'SEEK_SET';
10my $file = "tf42-$$.txt";
11
12BEGIN
13  {
14  $| = 1;
15  unshift @INC, File::Spec->catdir(File::Spec->updir, 'lib');
16  chdir 't' if -d 't';
17  print "# INC = @INC\n";
18
19  plan tests => 24;
20
21  use_ok ('Tie::File');
22  }
23
24$/ = "#";	# avoid problems with \n\r vs. \n
25
26my @a;
27my $o = tie @a, 'Tie::File', $file, autodefer => 0;
28
29is (ref($o), 'Tie::File');
30
31is ($o->offset(0), 0, 'first one always there');
32is ($o->offset(1), undef, 'no offsets yet');
33
34$a[0] = 'Bourbon';
35is ($o->offset(0), 0, 'first is ok');
36is ($o->offset(1), 8, 'and second ok');
37is ($o->offset(2), undef, 'third undef');
38
39$a[1] = 'makes';
40is ($o->offset(0), 0, 'first is ok');
41is ($o->offset(1), 8, 'and second ok');
42is ($o->offset(2), 14, 'and third ok');
43is ($o->offset(3), undef, 'fourth undef');
44
45$a[2] = 'the baby';
46is ($o->offset(0), 0, 'first is ok');
47is ($o->offset(1), 8, 'and second ok');
48is ($o->offset(2), 14, 'and third ok');
49is ($o->offset(3), 23, 'and fourth ok');
50is ($o->offset(4), undef, 'fourth undef');
51
52$a[3] = 'grin';
53is ($o->offset(0), 0, 'first is ok');
54is ($o->offset(1), 8, 'and second ok');
55is ($o->offset(2), 14, 'and third ok');
56is ($o->offset(3), 23, 'and fourth ok');
57is ($o->offset(4), 28, 'and fifth ok');
58
59$a[4] = '!';
60is ($o->offset(5), 30, 'and fifth ok');
61$a[3] = 'water';
62is ($o->offset(4), 29, 'and fourth changed ok');
63is ($o->offset(5), 31, 'and fifth ok');
64
65END {
66  undef $o;
67  untie @a;
68  1 while unlink $file;
69}
70