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.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 => 2; 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
12 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
13 14
14 my $rd_ae = AnyEvent::Handle->new (fh => $rd); 15 my $rd_ae = AnyEvent::Handle->new (
16 fh => $rd,
17 on_eof => sub { $cv->broadcast },
18 );
19
15 my $concat; 20 my $concat;
16 21
17 $rd_ae->on_eof (sub { $cv->broadcast });
18 $rd_ae->readlines (sub { 22 $rd_ae->push_read (line => sub {
19 my ($rd_ae, @lines) = @_; 23 is ($_[1], "A", 'A line was read correctly');
20 for (@lines) { 24 my $cb; $cb = sub {
21 chomp;
22 $concat .= $_; 25 $concat .= $_[1];
26 $_[0]->push_read (line => $cb);
23 } 27 };
28 $_[0]->push_read (line => $cb);
24 }); 29 });
25 30
26 $wr->syswrite ("A\nBC\nDEF\nG\n"); 31 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
27 $wr->syswrite (("X" x 113) . "\n"); 32 close $wr;
28 $wr->close;
29 33
30 $cv->wait; 34 $cv->wait;
31
32 is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly'); 35 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly');
33} 36}
34 37
35{ 38{
36 my $cv = AnyEvent->condvar; 39 my $cv = AnyEvent->condvar;
37 40
39 42
40 my $concat; 43 my $concat;
41 44
42 my $rd_ae = 45 my $rd_ae =
43 AnyEvent::Handle->new ( 46 AnyEvent::Handle->new (
44 fh => $rd, 47 fh => $rd,
45 on_eof => sub { $cv->broadcast }, 48 on_eof => sub { $cv->broadcast },
46 on_readline => sub { 49 on_read => sub {
47 my ($rd_ae, @lines) = @_; 50 $_[0]->push_read (line => sub {
48 for (@lines) {
49 chomp;
50 $concat .= $_; 51 $concat .= "$_[1]:";
51 } 52 });
52 } 53 }
53 ); 54 );
54 55
55 $wr->syswrite ("A\nBC\nDEF\nG\n"); 56 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
56 $wr->syswrite (("X" x 113) . "\n"); 57
57 $wr->close; 58 $wr_ae->push_write (netstring => "0:xx,,");
59 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
60 undef $wr;
61 undef $wr_ae;
62
63 $rd_ae->push_read (netstring => sub {
64 is ($_[1], "0:xx,,");
65 });
58 66
59 $cv->wait; 67 $cv->wait;
60 68
61 is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly'); 69 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
62} 70}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines