File: 23client-cap.t

package info (click to toggle)
libprotocol-irc-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 2,122; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 974 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test::More;

my $CRLF = "\x0d\x0a"; # because \r\n isn't portable

my @messages;

package TestIRC {
   use base qw( Protocol::IRC::Client );

   sub new { return bless {}, shift }

   sub on_message_cap
   {
      my $self = shift;
      my ( $verb, $message, $hints ) = @_;
      push @messages, [ $verb, $message, $hints ];
   }
}

my $irc = TestIRC->new;
sub write_irc
{
   my $line = $_[0];
   $irc->on_read( $line );
   length $line == 0 or die '$irc failed to read all of the line';
}

write_irc( ':irc.example.com CAP * LS :multi-prefix sasl' . $CRLF );

my ( $verb, $msg, $hints ) = @{ shift @messages };

is( $msg->command, "CAP", '$msg->command' );
is( $msg->arg(1),  "LS",  '$msg->arg' );

is( $verb,          "LS", '$verb' );
is( $hints->{verb}, "LS", '$hints->{verb}' );
is_deeply( $hints->{caps},
           { "multi-prefix" => 1,
             "sasl"         => 1 },
           '$hints->{caps}' );

done_testing;