File: 53loop-extend.t

package info (click to toggle)
libio-async-perl 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,068 kB
  • ctags: 491
  • sloc: perl: 12,530; makefile: 8
file content (103 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download | duplicates (5)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl

use strict;
use warnings;

use IO::Async::Test;

use Test::More;
use Test::Identity;

use IO::Async::Loop;

my $loop = IO::Async::Loop->new_builtin;

testing_loop( $loop );

# connect
{
   my %connectargs;
   my $connect_future;
   sub IO::Async::Loop::FOO_connect
   {
      my $self = shift;
      %connectargs = @_;

      identical( $self, $loop, 'FOO_connect invocant is $loop' );

      return $connect_future = $loop->new_future;
   }

   my $sock;
   my $f = $loop->connect(
      extensions => [qw( FOO )],
      some_param => "here",
      on_connected => sub { $sock = shift },
   );

   is( ref delete $connectargs{on_connected}, "CODE", 'FOO_connect received on_connected continuation' );
   is_deeply( \%connectargs,
              { some_param => "here" },
              'FOO_connect received some_param and no others' );

   identical( $f, $connect_future, 'FOO_connect returns Future object' );

   $loop->connect(
      extensions => [qw( FOO BAR )],
      param1 => "one",
      param2 => "two",
      on_connected => sub { $sock = shift },
   );

   delete $connectargs{on_connected};
   is_deeply( \%connectargs,
              { extensions => [qw( BAR )],
                param1 => "one",
                param2 => "two" },
              'FOO_connect still receives other extensions' );
}

# listen
{
   my %listenargs;
   my $listen_future;
   sub IO::Async::Loop::FOO_listen
   {
      my $self = shift;
      %listenargs = @_;

      identical( $self, $loop, 'FOO_listen invocant is $loop' );

      return $listen_future = $loop->new_future;
   }

   my $sock;
   my $f = $loop->listen(
      extensions => [qw( FOO )],
      some_param => "here",
      on_accept => sub { $sock = shift },
   );

   isa_ok( delete $listenargs{listener}, "IO::Async::Listener", '$listenargs{listener}' );
   is_deeply( \%listenargs,
              { some_param => "here" },
              'FOO_listen received some_param and no others' );

   identical( $f, $listen_future, 'FOO_listen returns Future object' );

   $loop->listen(
      extensions => [qw( FOO BAR )],
      param1 => "one",
      param2 => "two",
      on_accept => sub { $sock = shift },
   );

   delete $listenargs{listener};
   is_deeply( \%listenargs,
              { extensions => [qw( BAR )],
                param1 => "one",
                param2 => "two" },
              'FOO_listen still receives other extensions' );
}

done_testing;