--- AnyEvent/t/handle/01_readline.t 2008/04/27 19:08:38 1.3 +++ AnyEvent/t/handle/01_readline.t 2008/05/03 12:17:35 1.4 @@ -3,7 +3,7 @@ use strict; use AnyEvent::Impl::Perl; use AnyEvent::Handle; -use Test::More tests => 2; +use Test::More tests => 3; use Socket; { @@ -11,25 +11,27 @@ socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; - my $rd_ae = AnyEvent::Handle->new (fh => $rd); + my $rd_ae = AnyEvent::Handle->new ( + fh => $rd, + on_eof => sub { $cv->broadcast }, + ); + my $concat; - $rd_ae->on_eof (sub { $cv->broadcast }); - $rd_ae->readlines (sub { - my ($rd_ae, @lines) = @_; - for (@lines) { - chomp; - $concat .= $_; - } + $rd_ae->push_read_line (sub { + is ($_[1], "A", 'A line was read correctly'); + my $cb; $cb = sub { + $concat .= $_[1]; + $_[0]->push_read_line ($cb); + }; + $_[0]->push_read_line ($cb); }); - $wr->syswrite ("A\nBC\nDEF\nG\n"); - $wr->syswrite (("X" x 113) . "\n"); - $wr->close; + syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; + close $wr; $cv->wait; - - is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly'); + is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); } { @@ -41,22 +43,22 @@ my $rd_ae = AnyEvent::Handle->new ( - fh => $rd, - on_eof => sub { $cv->broadcast }, - on_readline => sub { - my ($rd_ae, @lines) = @_; - for (@lines) { - chomp; - $concat .= $_; - } + fh => $rd, + on_eof => sub { $cv->broadcast }, + on_read => sub { + $_[0]->push_read_line (sub { + $concat .= "$_[1]:"; + }); } ); - $wr->syswrite ("A\nBC\nDEF\nG\n"); - $wr->syswrite (("X" x 113) . "\n"); - $wr->close; + my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; + + $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); + undef $wr; + undef $wr_ae; $cv->wait; - is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly'); + is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); }