]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - test/plugins/test_points.rb
d29b6174e44a541ac7aca01d35d9d5d6ccbdb5c3
[user/henk/code/ruby/rbot.git] / test / plugins / test_points.rb
1 $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2 $:.unshift File.join(File.dirname(__FILE__), '..', '..')
3
4 require 'test/unit'
5 require 'test/mock'
6
7 require 'rbot/ircbot'
8 require 'rbot/registry'
9 require 'rbot/plugins'
10 require 'rbot/language'
11
12 class PointsPluginTest < Test::Unit::TestCase
13   def setup
14     manager = Irc::Bot::Plugins.manager
15     manager.bot_associate(MockBot.new)
16     manager.load_botmodule_file('./data/rbot/plugins/points.rb')
17     @plugin = manager.get_plugin('points')
18   end
19
20   def test_points
21     assert_not_nil(@plugin)
22     assert_not_empty(@plugin.help(nil))
23
24     m = MockMessage.new('', 'user')
25     @plugin.points(m, key: 'linux')
26     assert_equal('linux has zero points', m.replies.first)
27
28     m = MockMessage.new('linux++', 'user')
29     @plugin.message(m)
30     assert_equal('linux now has 1 points!', m.replies.first)
31
32     m = MockMessage.new('linux++', 'user')
33     @plugin.message(m)
34     assert_equal('linux now has 2 points!', m.replies.first)
35
36     m = MockMessage.new('linux++', 'linux')
37     @plugin.message(m)
38     assert_empty(m.replies)
39
40     m = MockMessage.new('', 'user')
41     @plugin.points(m, key: 'linux')
42     assert_equal('points for linux: 2', m.replies.first)
43
44     m = MockMessage.new('', 'linux')
45     @plugin.points(m, {})
46     assert_equal('points for linux: 2', m.replies.first)
47
48     m = MockMessage.new('alice++', 'user')
49     @plugin.message(m)
50     assert_equal('alice now has 1 points!', m.replies.first)
51
52     # assign to multiple things
53     m = MockMessage.new('hello linux++ hello torvalds++', 'user')
54     @plugin.message(m)
55     assert_equal(m.replies.length, 2)
56     assert_equal('linux now has 3 points!', m.replies[0])
57     assert_equal('torvalds now has 1 points!', m.replies[1])
58
59     ignored = [
60       '++alice',
61       '--alice',
62       'something something --github',
63       'ls --sort time',
64       '-- foo',
65       '++ foo',
66       'test ++',
67       'test --',
68       '<-- pointing',
69       'pointing -->',
70       '&++',
71       ' ++',
72       ' --',
73       '++ --',
74       '-- ++',
75       'https://linux.slashdot.org/story/20/04/12/2138205/how-red-hats-new-ceo-handles-life-under-ibm----and-a-global-pandemic'
76     ]
77     ignored.each do |ignore|
78       m = MockMessage.new(ignore, 'user')
79       @plugin.message(m)
80       assert_empty(m.replies, "message should've been ignored: #{ignore.inspect}")
81     end
82
83     m = MockMessage.new('bob++', 'user')
84     @plugin.message(m)
85     assert_equal('bob now has 1 points!', m.replies.first)
86
87     m = MockMessage.new('bot++', 'user')
88     @plugin.message(m)
89     assert_equal('thanks :)', m.replies.first)
90   end
91 end