xref: /openbsd-src/gnu/usr.bin/perl/cpan/IO-Zlib/t/getline.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1use strict;
2use warnings;
3
4use IO::Zlib;
5
6sub ok
7{
8    my ($no, $ok) = @_ ;
9    print "ok $no\n" if $ok ;
10    print "not ok $no\n" unless $ok ;
11}
12
13my $name = "test_getline_$$.gz";
14
15print "1..23\n";
16
17my @text = (<<EOM, <<EOM, <<EOM, <<EOM) ;
18this is line 1
19EOM
20the second line
21EOM
22the line after the previous line
23EOM
24the final line
25EOM
26
27my $text = join("", @text) ;
28my $file;
29
30ok(1, $file = IO::Zlib->new($name, "wb"));
31ok(2, $file->print($text));
32ok(3, $file->close());
33
34ok(4, $file = IO::Zlib->new($name, "rb"));
35ok(5, !$file->eof());
36ok(6, $file->getline() eq $text[0]);
37ok(7, $file->getline() eq $text[1]);
38ok(8, $file->getline() eq $text[2]);
39ok(9, $file->getline() eq $text[3]);
40ok(10, !defined($file->getline()));
41ok(11, $file->eof());
42ok(12, $file->close());
43
44my @lines;
45
46ok(13, $file = IO::Zlib->new($name, "rb"));
47ok(14, !$file->eof());
48eval '$file->getlines';
49ok(15, $@ =~ /^IO::Zlib::getlines: must be called in list context /);
50ok(16, @lines = $file->getlines());
51ok(17, @lines == @text);
52ok(18, $lines[0] eq $text[0]);
53ok(19, $lines[1] eq $text[1]);
54ok(20, $lines[2] eq $text[2]);
55ok(21, $lines[3] eq $text[3]);
56ok(22, $file->eof());
57ok(23, $file->close());
58
59unlink($name);
60