This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Scalar-List-Utils to CPAN version 1.26
[perl5.git] / cpan / IO-Zlib / t / getline.t
1 use IO::Zlib;
2
3 sub ok
4 {
5     my ($no, $ok) = @_ ;
6
7     #++ $total ;
8     #++ $totalBad unless $ok ;
9
10     print "ok $no\n" if $ok ;
11     print "not ok $no\n" unless $ok ;
12 }
13
14 $name="test.gz";
15
16 print "1..23\n";
17
18 @text = (<<EOM, <<EOM, <<EOM, <<EOM) ;
19 this is line 1
20 EOM
21 the second line
22 EOM
23 the line after the previous line
24 EOM
25 the final line
26 EOM
27
28 $text = join("", @text) ;
29
30 ok(1, $file = IO::Zlib->new($name, "wb"));
31 ok(2, $file->print($text));
32 ok(3, $file->close());
33
34 ok(4, $file = IO::Zlib->new($name, "rb"));
35 ok(5, !$file->eof());
36 ok(6, $file->getline() eq $text[0]);
37 ok(7, $file->getline() eq $text[1]);
38 ok(8, $file->getline() eq $text[2]);
39 ok(9, $file->getline() eq $text[3]);
40 ok(10, !defined($file->getline()));
41 ok(11, $file->eof());
42 ok(12, $file->close());
43
44 ok(13, $file = IO::Zlib->new($name, "rb"));
45 ok(14, !$file->eof());
46 eval '$file->getlines';
47 ok(15, $@ =~ /^IO::Zlib::getlines: must be called in list context /);
48 ok(16, @lines = $file->getlines());
49 ok(17, @lines == @text);
50 ok(18, $lines[0] eq $text[0]);
51 ok(19, $lines[1] eq $text[1]);
52 ok(20, $lines[2] eq $text[2]);
53 ok(21, $lines[3] eq $text[3]);
54 ok(22, $file->eof());
55 ok(23, $file->close());
56
57 unlink($name);