newton 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestParse < Test::Unit::TestCase
4
+ test "ping-pong" do
5
+ bot = mock_bot {}
6
+ bot_is_connected
7
+
8
+ @server.print "PING :foo.bar\r\n"
9
+ assert_equal "PONG :foo.bar\r\n", @server.gets
10
+ end
11
+
12
+ test "join messages dispatches join event" do
13
+ bot = mock_bot {
14
+ on(:join) {msg channel, "bar baz"}
15
+ }
16
+ bot_is_connected
17
+
18
+ @server.print ":johnny!john@doe.com JOIN #foo\r\n"
19
+ assert_equal "PRIVMSG #foo :bar baz\r\n", @server.gets
20
+ end
21
+
22
+ test "part messages dispatches part events" do
23
+ bot = mock_bot {
24
+ on(:part) {msg channel, "#{nick} left: #{message}"}
25
+ }
26
+ bot_is_connected
27
+
28
+ @server.print ":johnny!john@doe.com PART #foo :Leaving\r\n"
29
+ assert_equal "PRIVMSG #foo :johnny left: Leaving\r\n", @server.gets
30
+ end
31
+
32
+ test "quit messages dispatches quit events" do
33
+ bot = mock_bot {
34
+ on(:quit) {msg "#foo", "#{nick} quit: #{message}"}
35
+ }
36
+ bot_is_connected
37
+
38
+ @server.print ":johnny!john@doe.com QUIT :Leaving\r\n"
39
+ assert_equal "PRIVMSG #foo :johnny quit: Leaving\r\n", @server.gets
40
+ end
41
+
42
+ test "private messages dispatches private event" do
43
+ bot = mock_bot {
44
+ on(:private, //) {msg "foo", "bar baz"}
45
+ }
46
+ bot_is_connected
47
+
48
+ @server.print ":johnny!john@doe.com PRIVMSG isaac :hello, you!\r\n"
49
+ assert_equal "PRIVMSG foo :bar baz\r\n", @server.gets
50
+ end
51
+
52
+ test "channel messages dispatches channel event" do
53
+ bot = mock_bot {
54
+ on(:channel, //) {msg "foo", "bar baz"}
55
+ }
56
+ bot_is_connected
57
+
58
+ @server.print ":johnny!john@doe.com PRIVMSG #awesome :hello, folks!\r\n"
59
+ assert_equal "PRIVMSG foo :bar baz\r\n", @server.gets
60
+ end
61
+
62
+ test "prefix is optional" do
63
+ bot = mock_bot {
64
+ on(:channel, //) {msg "foo", "bar baz"}
65
+ }
66
+ bot_is_connected
67
+
68
+ @server.print "PRIVMSG #awesome :hello, folks!\r\n"
69
+ assert_equal "PRIVMSG foo :bar baz\r\n", @server.gets
70
+ end
71
+
72
+ test "private event has environment" do
73
+ bot = mock_bot {
74
+ on :private, // do
75
+ raw nick
76
+ raw user.user
77
+ raw host
78
+ raw message
79
+ end
80
+ }
81
+ bot_is_connected
82
+
83
+ @server.puts ":johnny!john@doe.com PRIVMSG isaac :hello, you!"
84
+ assert_equal "johnny\r\n", @server.gets
85
+ assert_equal "john\r\n", @server.gets
86
+ assert_equal "doe.com\r\n", @server.gets
87
+ assert_equal "hello, you!\r\n", @server.gets
88
+ end
89
+
90
+ test "channel event has environment" do
91
+ bot = mock_bot {
92
+ on :channel, // do
93
+ raw nick
94
+ raw user.user
95
+ raw host
96
+ raw message
97
+ raw channel.to_s
98
+ end
99
+ }
100
+ bot_is_connected
101
+
102
+ @server.puts ":johnny!john@doe.com PRIVMSG #awesome :hello, folks!"
103
+ assert_equal "johnny\r\n", @server.gets
104
+ assert_equal "john\r\n", @server.gets
105
+ assert_equal "doe.com\r\n", @server.gets
106
+ assert_equal "hello, folks!\r\n", @server.gets
107
+ assert_equal "#awesome\r\n", @server.gets
108
+ end
109
+
110
+ test "errors are caught and dispatched" do
111
+ bot = mock_bot {
112
+ on(:error, 401) {
113
+ raw error
114
+ }
115
+ }
116
+ bot_is_connected
117
+
118
+ @server.print ":server 401 isaac jeff :No such nick/channel\r\n"
119
+ assert_equal "401\r\n", @server.gets
120
+ end
121
+
122
+ test "prefix is optional for errors" do
123
+ bot = mock_bot {
124
+ on(:error, 401) {
125
+ raw error
126
+ }
127
+ }
128
+ bot_is_connected
129
+
130
+ @server.print "401 isaac jeff :No such nick/channel\r\n"
131
+ assert_equal "401\r\n", @server.gets
132
+ end
133
+
134
+ # test "ctcp version request are answered" do
135
+ # bot = mock_bot {
136
+ # configure {|c| c.version = "Ridgemont 0.1"}
137
+ # }
138
+ # bot_is_connected
139
+
140
+ # @server.print ":jeff!spicoli@name.com PRIVMSG isaac :\001VERSION\001\r\n"
141
+ # assert_equal "NOTICE jeff :\001VERSION Ridgemont 0.1\001\r\n", @server.gets
142
+ # end
143
+
144
+ test "trailing newlines are removed" do
145
+ bot = mock_bot {
146
+ on(:channel, /(.*)/) {msg "foo", "#{match[0]} he said"}
147
+ }
148
+ bot_is_connected
149
+
150
+ @server.print ":johnny!john@doe.com PRIVMSG #awesome :hello, folks!\r\n"
151
+ assert_equal "PRIVMSG foo :hello, folks! he said\r\n", @server.gets
152
+ end
153
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestQueue < Test::Unit::TestCase
4
+ def flood_bot
5
+ bot = mock_bot {
6
+ on(:connect) {
7
+ # 1472.0 / 16 = 92.0, minus one to accomodate for newline
8
+ 16.times { raw "." * 90 }
9
+ raw "this should not flood!"
10
+ }
11
+ }
12
+ bot_is_connected
13
+ # We don't want to account for the initial NIKC/USER messages
14
+ bot.irc.instance_variable_set :@transfered, 0
15
+ bot
16
+ end
17
+
18
+
19
+ test "ping after sending 1472 consequent bytes" do
20
+ bot = flood_bot
21
+
22
+ bot.dispatch :connect
23
+ 16.times { @server.gets }
24
+ assert_equal "PING :#{bot.config.server}\r\n", @server.gets
25
+ assert @server.empty?
26
+ end
27
+
28
+ test "reset transfer amount at pong reply" do
29
+ bot = flood_bot
30
+
31
+ bot.dispatch :connect
32
+ 16.times { @server.gets }
33
+ @server.gets # PING message
34
+
35
+ @server.puts ":localhost PONG :localhost"
36
+ assert_equal "this should not flood!\r\n", @server.gets
37
+ end
38
+
39
+ test "reset transfer amount at server ping" do
40
+ bot = flood_bot
41
+
42
+ bot.dispatch :connect
43
+ 16.times { @server.gets }
44
+ @server.gets # PING message triggered by transfer lock
45
+ @server.puts "PING :localhost"
46
+
47
+ assert_equal "this should not flood!\r\n", @server.gets
48
+ end
49
+ end
data/test/tests.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "test/unit"
2
+ require "test_commands.rb"
3
+ require "test_events.rb"
4
+ require "test_helpers.rb"
5
+ require "test_irc.rb"
6
+ require "test_message.rb"
7
+ require "test_parse.rb"
8
+ require "test_queue.rb"
9
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newton
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dominik Honnef
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-18 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: "Newton \xE2\x80\x93 Adding new forces to your bots."
22
+ email: dominikh@fork-bomb.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - lib/newton.rb
32
+ - lib/newton/irc.rb
33
+ - lib/newton/mask.rb
34
+ - lib/newton/formatted_logger.rb
35
+ - lib/newton/exceptions.rb
36
+ - lib/newton/rubyext/module.rb
37
+ - lib/newton/rubyext/queue.rb
38
+ - lib/newton/rubyext/string.rb
39
+ - lib/newton/rubyext/infinity.rb
40
+ - lib/newton/channel.rb
41
+ - lib/newton/message.rb
42
+ - lib/newton/bot.rb
43
+ - lib/newton/user.rb
44
+ - lib/newton/constants.rb
45
+ - lib/newton/callback.rb
46
+ - lib/newton/syncable.rb
47
+ - lib/newton/message_queue.rb
48
+ - lib/newton/ban.rb
49
+ - lib/newton/isupport.rb
50
+ - test/test_message.rb
51
+ - test/test_commands.rb
52
+ - test/test_irc.rb
53
+ - test/helper.rb
54
+ - test/test_helpers.rb
55
+ - test/tests.rb
56
+ - test/test_queue.rb
57
+ - test/test_parse.rb
58
+ - test/test_events.rb
59
+ - examples/schema.rb
60
+ - examples/autovoice.rb
61
+ - examples/secure_eval.rb
62
+ - examples/excess_flood.rb
63
+ - examples/echo_bot.rb
64
+ - examples/memo.rb
65
+ - README.md
66
+ - LICENSE
67
+ has_rdoc: yard
68
+ homepage: http://github.com/dominikh/isaac
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 1
82
+ - 9
83
+ - 1
84
+ version: 1.9.1
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: "Newton \xE2\x80\x93 Adding new forces to your bots."
99
+ test_files: []
100
+