source: trunk/essentials/dev-lang/perl/ext/IO/t/io_linenum.t

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 1.4 KB
Line 
1#!./perl
2
3# test added 29th April 1999 by Paul Johnson ([email protected])
4# updated 28th May 1999 by Paul Johnson
5
6my $File;
7
8BEGIN {
9 $File = __FILE__;
10 unless(grep /blib/, @INC) {
11 chdir 't' if -d 't';
12 $File =~ s/^t\W+//; # Remove first directory
13 @INC = '../lib';
14 }
15 require strict; import strict;
16}
17
18use Test;
19
20BEGIN { plan tests => 12 }
21
22use IO::File;
23
24sub lineno
25{
26 my ($f) = @_;
27 my $l;
28 $l .= "$. ";
29 $l .= $f->input_line_number;
30 $l .= " $."; # check $. before and after input_line_number
31 $l;
32}
33
34my $t;
35
36open (F, $File) or die $!;
37my $io = IO::File->new($File) or die $!;
38
39<F> for (1 .. 10);
40ok(lineno($io), "10 0 10");
41
42$io->getline for (1 .. 5);
43ok(lineno($io), "5 5 5");
44
45<F>;
46ok(lineno($io), "11 5 11");
47
48$io->getline;
49ok(lineno($io), "6 6 6");
50
51$t = tell F; # tell F; provokes a warning
52ok(lineno($io), "11 6 11");
53
54<F>;
55ok(lineno($io), "12 6 12");
56
57select F;
58ok(lineno($io), "12 6 12");
59
60<F> for (1 .. 10);
61ok(lineno($io), "22 6 22");
62
63$io->getline for (1 .. 5);
64ok(lineno($io), "11 11 11");
65
66$t = tell F;
67# We used to have problems here before local $. worked.
68# input_line_number() used to use select and tell. When we did the
69# same, that mechanism broke. It should work now.
70ok(lineno($io), "22 11 22");
71
72{
73 local $.;
74 $io->getline for (1 .. 5);
75 ok(lineno($io), "16 16 16");
76}
77
78ok(lineno($io), "22 16 22");
Note: See TracBrowser for help on using the repository browser.