Wrap the macro arguments for ck_proto in ().
[p5sagit/p5-mst-13.2.git] / lib / Tie / File / t / 42_offset.t
CommitLineData
6ae23f41 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 = "tf$$.txt";
11
12BEGIN
13 {
14 $| = 1;
15 if ($ENV{PERL_CORE})
16 {
17 # testing with the core distribution
18 @INC = ( File::Spec->catdir(File::Spec->updir, 't', 'lib') );
19 }
20 unshift @INC, File::Spec->catdir(File::Spec->updir, 'lib');
21 chdir 't' if -d 't';
22 print "# INC = @INC\n";
23
24 plan tests => 24;
25
26 use_ok ('Tie::File');
27 }
28
29$/ = "#"; # avoid problems with \n\r vs. \n
30
31my @a;
32my $o = tie @a, 'Tie::File', $file, autodefer => 0;
33
34is (ref($o), 'Tie::File');
35
36is ($o->offset(0), 0, 'first one always there');
37is ($o->offset(1), undef, 'no offsets yet');
38
39$a[0] = 'Bourbon';
40is ($o->offset(0), 0, 'first is ok');
41is ($o->offset(1), 8, 'and second ok');
42is ($o->offset(2), undef, 'third undef');
43
44$a[1] = 'makes';
45is ($o->offset(0), 0, 'first is ok');
46is ($o->offset(1), 8, 'and second ok');
47is ($o->offset(2), 14, 'and third ok');
48is ($o->offset(3), undef, 'fourth undef');
49
50$a[2] = 'the baby';
51is ($o->offset(0), 0, 'first is ok');
52is ($o->offset(1), 8, 'and second ok');
53is ($o->offset(2), 14, 'and third ok');
54is ($o->offset(3), 23, 'and fourth ok');
55is ($o->offset(4), undef, 'fourth undef');
56
57$a[3] = 'grin';
58is ($o->offset(0), 0, 'first is ok');
59is ($o->offset(1), 8, 'and second ok');
60is ($o->offset(2), 14, 'and third ok');
61is ($o->offset(3), 23, 'and fourth ok');
62is ($o->offset(4), 28, 'and fifth ok');
63
64$a[4] = '!';
65is ($o->offset(5), 30, 'and fifth ok');
66$a[3] = 'water';
67is ($o->offset(4), 29, 'and fourth changed ok');
68is ($o->offset(5), 31, 'and fifth ok');
69
70END {
71 undef $o;
72 untie @a;
73 1 while unlink $file;
74}