File: 22client-chanmodes.t

package info (click to toggle)
libprotocol-irc-perl 0.12-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 268 kB
  • sloc: perl: 2,115; makefile: 2
file content (174 lines) | stat: -rw-r--r-- 5,716 bytes parent folder | download | duplicates (2)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

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

my @messages;

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';
}

ok( defined $irc, 'defined $irc' );

write_irc( ':irc.example.com 005 MyNick NAMESX PREFIX=(ohv)@%+ CHANMODES=beI,k,l,imnpst :are supported by this server' . $CRLF );

undef @messages;

write_irc( ':Someone!theiruser@their.host MODE #chan +i' . $CRLF );

my ( $command, $msg, $hints );
my $modes;

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

is( $msg->command, "MODE",                         '$msg->command for +i' );
is( $msg->prefix,  'Someone!theiruser@their.host', '$msg->prefix for +i' );
is_deeply( [ $msg->args ], [ "#chan", "+i" ],      '$msg->args for +i' );

is_deeply( $hints,
           { prefix_nick        => "Someone",
             prefix_nick_folded => "someone",
             prefix_user        => "theiruser",
             prefix_host        => "their.host",
             prefix_name        => "Someone",
             prefix_name_folded => "someone",
             prefix_is_me       => '',
             target_name        => "#chan",
             target_name_folded => "#chan",
             target_is_me       => '',
             target_type        => "channel",
             modechars          => "+i",
             modeargs           => [ ],
             modes              => [
                { type          => 'bool',
                  sense         => 1,
                  mode          => "i" } ],
             handled            => 1 }, '$hints for +i' );

write_irc( ':Someone!theiruser@their.host MODE #chan -i' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes,
           [ { type => 'bool', sense => -1, mode => "i" } ],
           '$modes for -i' );

write_irc( ':Someone!theiruser@their.host MODE #chan +b *!bad@bad.host' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes,
           [ { type => 'list', sense => 1, mode => "b", value => "*!bad\@bad.host" } ],
           '$modes for +b ...' );

write_irc( ':Someone!theiruser@their.host MODE #chan -b *!less@bad.host' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes,
           [ { type => 'list', sense => -1, mode => "b", value => "*!less\@bad.host" }, ],
           '$hints for -b ...' );

write_irc( ':Someone!theiruser@their.host MODE #chan +o OpUser' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'occupant', sense => 1, mode => "o", flag => '@', nick => "OpUser", nick_folded => "opuser" } ],
           '$modes[chanmode] for +o OpUser' );

write_irc( ':Someone!theiruser@their.host MODE #chan -o OpUser' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'occupant', sense => -1, mode => "o", flag => '@', nick => "OpUser", nick_folded => "opuser" } ],
           '$modes[chanmode] for -o OpUser' );

write_irc( ':Someone!theiruser@their.host MODE #chan +k joinkey' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'value', sense => 1, mode => "k", value => "joinkey" } ],
           '$modes[chanmode] for +k joinkey' );

write_irc( ':Someone!theiruser@their.host MODE #chan -k joinkey' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'value', sense => -1, mode => "k", value => "joinkey" } ],
           '$modes[chanmode] for -k joinkey' );

write_irc( ':Someone!theiruser@their.host MODE #chan +l 30' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'value', sense => 1, mode => "l", value => "30" } ],
           '$modes[chanmode] for +l 30' );

write_irc( ':Someone!theiruser@their.host MODE #chan -l' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes, 
           [ { type => 'value', sense => -1, mode => "l" } ],
           '$modes[chanmode] for -l' );

write_irc( ':Someone!theiruser@their.host MODE #chan +shl HalfOp 123' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes,
           [ { type => 'bool',     sense => 1, mode => "s" },
             { type => 'occupant', sense => 1, mode => "h", flag => '%', nick => "HalfOp", nick_folded => "halfop" },
             { type => 'value',    sense => 1, mode => "l", value => "123" } ],
           '$modes[chanmode] for +shl HalfOp 123' );

write_irc( ':Someone!theiruser@their.host MODE #chan -lh+o HalfOp FullOp' . $CRLF );

( $command, $msg, $hints ) = @{ shift @messages };
$modes = $hints->{modes};

is_deeply( $modes,
           [ { type => 'value',    sense => -1, mode => "l" },
             { type => 'occupant', sense => -1, mode => "h", flag => '%', nick => "HalfOp", nick_folded => "halfop", },
             { type => 'occupant', sense =>  1, mode => "o", flag => '@', nick => "FullOp", nick_folded => "fullop" } ],
           '$modes[chanmode] for -lh+o HalfOp FullOp' );

done_testing;

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

sub new { return bless {}, shift }

sub nick { return "MyNick" }

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