ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
(Generate patch)

Comparing AnyEvent/t/handle/01_readline.t (file contents):
Revision 1.3 by root, Sun Apr 27 19:08:38 2008 UTC vs.
Revision 1.4 by root, Sat May 3 12:17:35 2008 UTC

1#!perl 1#!perl
2 2
3use strict; 3use strict;
4use AnyEvent::Impl::Perl; 4use AnyEvent::Impl::Perl;
5use AnyEvent::Handle; 5use AnyEvent::Handle;
6use Test::More tests => 2; 6use Test::More tests => 3;
7use Socket; 7use Socket;
8 8
9{ 9{
10 my $cv = AnyEvent->condvar; 10 my $cv = AnyEvent->condvar;
11 11
12 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 12 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
13 13
14 my $rd_ae = AnyEvent::Handle->new (fh => $rd); 14 my $rd_ae = AnyEvent::Handle->new (
15 fh => $rd,
16 on_eof => sub { $cv->broadcast },
17 );
18
15 my $concat; 19 my $concat;
16 20
17 $rd_ae->on_eof (sub { $cv->broadcast });
18 $rd_ae->readlines (sub { 21 $rd_ae->push_read_line (sub {
19 my ($rd_ae, @lines) = @_; 22 is ($_[1], "A", 'A line was read correctly');
20 for (@lines) { 23 my $cb; $cb = sub {
21 chomp;
22 $concat .= $_; 24 $concat .= $_[1];
25 $_[0]->push_read_line ($cb);
23 } 26 };
27 $_[0]->push_read_line ($cb);
24 }); 28 });
25 29
26 $wr->syswrite ("A\nBC\nDEF\nG\n"); 30 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
27 $wr->syswrite (("X" x 113) . "\n"); 31 close $wr;
28 $wr->close;
29 32
30 $cv->wait; 33 $cv->wait;
31
32 is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly'); 34 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly');
33} 35}
34 36
35{ 37{
36 my $cv = AnyEvent->condvar; 38 my $cv = AnyEvent->condvar;
37 39
39 41
40 my $concat; 42 my $concat;
41 43
42 my $rd_ae = 44 my $rd_ae =
43 AnyEvent::Handle->new ( 45 AnyEvent::Handle->new (
44 fh => $rd, 46 fh => $rd,
45 on_eof => sub { $cv->broadcast }, 47 on_eof => sub { $cv->broadcast },
46 on_readline => sub { 48 on_read => sub {
47 my ($rd_ae, @lines) = @_; 49 $_[0]->push_read_line (sub {
48 for (@lines) {
49 chomp;
50 $concat .= $_; 50 $concat .= "$_[1]:";
51 } 51 });
52 } 52 }
53 ); 53 );
54 54
55 $wr->syswrite ("A\nBC\nDEF\nG\n"); 55 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
56 $wr->syswrite (("X" x 113) . "\n"); 56
57 $wr->close; 57 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
58 undef $wr;
59 undef $wr_ae;
58 60
59 $cv->wait; 61 $cv->wait;
60 62
61 is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly'); 63 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
62} 64}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines