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.4 by root, Sat May 3 12:17:35 2008 UTC vs.
Revision 1.7 by root, Sat May 24 23:15:14 2008 UTC

1#!perl 1#!perl
2 2
3use strict; 3use strict;
4
4use AnyEvent::Impl::Perl; 5use AnyEvent::Impl::Perl;
5use AnyEvent::Handle; 6use AnyEvent::Handle;
6use Test::More tests => 3; 7use Test::More tests => 4;
7use Socket; 8use Socket;
8 9
9{ 10{
10 my $cv = AnyEvent->condvar; 11 my $cv = AnyEvent->condvar;
11 12
16 on_eof => sub { $cv->broadcast }, 17 on_eof => sub { $cv->broadcast },
17 ); 18 );
18 19
19 my $concat; 20 my $concat;
20 21
21 $rd_ae->push_read_line (sub { 22 $rd_ae->push_read (line => sub {
22 is ($_[1], "A", 'A line was read correctly'); 23 is ($_[1], "A", 'A line was read correctly');
23 my $cb; $cb = sub { 24 my $cb; $cb = sub {
24 $concat .= $_[1]; 25 $concat .= $_[1];
25 $_[0]->push_read_line ($cb); 26 $_[0]->push_read (line => $cb);
26 }; 27 };
27 $_[0]->push_read_line ($cb); 28 $_[0]->push_read (line => $cb);
28 }); 29 });
29 30
30 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; 31 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
31 close $wr; 32 close $wr;
32 33
44 my $rd_ae = 45 my $rd_ae =
45 AnyEvent::Handle->new ( 46 AnyEvent::Handle->new (
46 fh => $rd, 47 fh => $rd,
47 on_eof => sub { $cv->broadcast }, 48 on_eof => sub { $cv->broadcast },
48 on_read => sub { 49 on_read => sub {
49 $_[0]->push_read_line (sub { 50 $_[0]->push_read (line => sub {
50 $concat .= "$_[1]:"; 51 $concat .= "$_[1]:";
51 }); 52 });
52 } 53 }
53 ); 54 );
54 55
55 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; 56 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
56 57
58 $wr_ae->push_write (netstring => "0:xx,,");
57 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); 59 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
58 undef $wr; 60 undef $wr;
59 undef $wr_ae; 61 undef $wr_ae;
62
63 $rd_ae->push_read (netstring => sub {
64 is ($_[1], "0:xx,,");
65 });
60 66
61 $cv->wait; 67 $cv->wait;
62 68
63 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); 69 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
64} 70}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines