Changeset 5595
- Timestamp:
- 01/27/08 07:34:35 (5 years ago)
- Location:
- lang/ruby/net-irc/trunk
- Files:
-
- 2 modified
-
lib/net/irc.rb (modified) (3 diffs)
-
test/net-irc_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/net-irc/trunk/lib/net/irc.rb
r5594 r5595 297 297 class Prefix < String 298 298 def nick 299 extract[0] 300 end 301 302 def user 299 303 extract[1] 300 304 end 301 305 302 def user306 def host 303 307 extract[2] 304 end305 306 def host307 extract[3]308 308 end 309 309 … … 402 402 include Constants 403 403 404 attr_reader :prefix 405 404 406 def initialize(host, port, opts={}) 405 407 @host = host … … 428 430 name = "on_#{(COMMANDS[m.command.upcase] || m.command).downcase}" 429 431 send(name, m) if respond_to?(name) 432 rescue Exception => e 433 warn e 434 warn e.backtrace.join("\r\t") 435 raise 430 436 rescue Message::InvalidMessage 431 437 @log.error "MessageParse: " + l.inspect -
lang/ruby/net-irc/trunk/test/net-irc_test.rb
r5555 r5595 33 33 end 34 34 35 def test_server 35 def test_server_client 36 36 port = rand(0xffff) + 1000 37 37 … … 45 45 46 46 Thread.start do 47 client = Net::IRC::Client.new("localhost", port, { 48 :nick => "chokan", 49 :user => "chokan", 50 :real => "chokan", 47 client = TestClient.new("localhost", port, { 48 :nick => "foonick", 49 :user => "foouser", 50 :real => "foo real name", 51 :pass => "foopass", 51 52 :out => StringIO.new, 52 53 }) … … 54 55 end 55 56 56 assert_equal "chokan!chokan@localhost", TestServerSession.testq.pop 57 assert_equal "PASS foopass\r\n", TestServerSession.testq.pop.to_s 58 assert_equal "NICK foonick\r\n", TestServerSession.testq.pop.to_s 59 assert_equal "USER foouser 0 * :foo real name\r\n", TestServerSession.testq.pop.to_s 60 assert_equal "WHOIS foonick\r\n", TestServerSession.testq.pop.to_s 61 62 assert_equal "001 foonick :Welcome to the Internet Relay Network foonick!foouser@localhost\r\n", TestClient.testq.pop.to_s 63 assert_equal "002 foonick :Your host is Net::IRC::Server::Session, running version 0.0.0\r\n", TestClient.testq.pop.to_s 64 57 65 client.instance_eval do 58 66 post PRIVMSG, "#channel", "message a b c" … … 62 70 assert_instance_of Net::IRC::Message, message 63 71 assert_equal "PRIVMSG #channel :message a b c\r\n", message.to_s 72 73 client.instance_variable_set(:@prefix, Prefix.new("foonick!foouser@localhost")) 74 75 # test channel management 76 TestServerSession.instance.instance_eval do 77 Thread.exclusive do 78 post client.prefix, JOIN, "#test" 79 post nil, NOTICE, "#test", "sep1" 80 81 post "test1!test@localhost", JOIN, "#test" 82 post "test2!test@localhost", JOIN, "#test" 83 post nil, NOTICE, "#test", "sep2" 84 85 post nil, RPL_NAMREPLY, client.prefix.nick, "@", "#test", "foo1 foo2 foo3 @foo4 +foo5" 86 post nil, NOTICE, "#test", "sep3" 87 end 88 end 89 90 while m = TestClient.testq.pop.to_s 91 break if m == "NOTICE #test sep1\r\n" 92 end 93 94 c = client.instance_variable_get(:@channels) 95 assert_instance_of Hash, c 96 assert_instance_of Hash, c["#test"] 97 assert_instance_of Array, c["#test"][:modes] 98 assert_instance_of Array, c["#test"][:users] 99 assert_equal ["foonick"], c["#test"][:users] 100 101 while m = TestClient.testq.pop.to_s 102 break if m == "NOTICE #test sep2\r\n" 103 end 104 105 assert_equal ["foonick", "test1", "test2"], c["#test"][:users] 106 107 while m = TestClient.testq.pop.to_s 108 break if m == "NOTICE #test sep3\r\n" 109 end 110 assert_equal ["foonick", "test1", "test2", "foo1", "foo2", "foo3", "foo4", "foo5"], c["#test"][:users] 111 assert c["#test"][:modes].include?(["s", nil]) 112 assert c["#test"][:modes].include?(["o", "foo4"]) 113 assert c["#test"][:modes].include?(["v", "foo5"]) 64 114 end 65 115 … … 81 131 end 82 132 83 def on_user(m) 84 super 85 @@testq << @mask 133 def on_message(m) 134 @@testq << m 135 end 136 end 137 138 class TestClient < Net::IRC::Client 139 @@testq = SizedQueue.new(1) 140 @@instance = nil 141 142 def self.testq 143 @@testq 86 144 end 87 145 88 def on_privmsg(m) 146 def self.instance 147 @@instance 148 end 149 150 def initialize(*args) 151 super 152 @@instance = self 153 end 154 155 def on_message(m) 89 156 @@testq << m 90 157 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)