home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / t / lib / io_linenum.t < prev    next >
Text File  |  1999-07-20  |  1KB  |  81 lines

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