File: iterator.t

package info (click to toggle)
libio-handle-util-perl 0.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 320 kB
  • sloc: perl: 1,353; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use ok 'IO::Handle::Iterator';
use ok 'IO::Handle::Util' => qw(io_from_array);

my $fh = &io_from_array([qw(foo bar gorch baz quxx la la dong)]);

isa_ok( $fh, "IO::Handle::Iterator" );
isa_ok( $fh, "IO::Handle" );

ok( !$fh->eof, "not eof" );

is( $fh->getline, "foo", "getline" );

ok( !$fh->eof, "not eof" );

is( $fh->read(my $buf, 2), 2, "read" );
is( $buf, "ba", "read buffer" );

ok( !$fh->eof, "not eof" );

is( $fh->read($buf, 2), 2, "read" );
is( $buf, "rg", "read buffer" );

ok( !$fh->eof, "not eof" );

is( $fh->getline, "orch", "getline" );
is( $fh->getline, "baz", "getline" );

ok( !$fh->eof, "not eof" );

is( $fh->read($buf, 7), 7, "read" );
is( $buf, "quxxlal", "read buffer" );

ok( !$fh->eof, "not eof" );

is( $fh->getc, 'a', "getc" );

ok( !$fh->eof, "not eof" );

$fh->ungetc(ord('z'));

ok( !$fh->eof, "not eof" );

is( $fh->getc(), 'z', "ungetc" );

ok( !$fh->eof, "not eof" );

is( $fh->read($buf, 7, length($buf) + 1), 4, "read" );
is( $buf, "quxxlal\0dong", "read buffer" );

ok( $fh->eof, "eof" );

done_testing;

# ex: set sw=4 et: