]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - test/plugins/test_points.rb
plugin(points): forgot one special case, see #34
[user/henk/code/ruby/rbot.git] / test / plugins / test_points.rb
index f1a7479dd49402093ebc9e9f39e95909652bd000..b3386ed4769196bdecc3cb61ec6b10215c327124 100644 (file)
@@ -21,6 +21,10 @@ class PointsPluginTest < Test::Unit::TestCase
     assert_not_nil(@plugin)
     assert_not_empty(@plugin.help(nil))
 
+    m = MockMessage.new('', 'user')
+    @plugin.points(m, key: 'linux')
+    assert_equal('linux has zero points', m.replies.first)
+
     m = MockMessage.new('linux++', 'user')
     @plugin.message(m)
     assert_equal('linux now has 1 points!', m.replies.first)
@@ -40,5 +44,50 @@ class PointsPluginTest < Test::Unit::TestCase
     m = MockMessage.new('', 'linux')
     @plugin.points(m, {})
     assert_equal('points for linux: 2', m.replies.first)
+
+    m = MockMessage.new('alice++', 'user')
+    @plugin.message(m)
+    assert_equal('alice now has 1 points!', m.replies.first)
+
+    # assign to multiple things
+    m = MockMessage.new('hello linux++ hello torvalds++', 'user')
+    @plugin.message(m)
+    assert_equal(m.replies.length, 2)
+    assert_equal('linux now has 3 points!', m.replies[0])
+    assert_equal('torvalds now has 1 points!', m.replies[1])
+
+    ignored = [
+      '++alice',
+      '--alice',
+      'something something --github',
+      'ls --sort time',
+      '-- foo',
+      '++ foo',
+      'test ++',
+      'test --',
+      '<-- pointing',
+      'pointing -->',
+      '&++',
+      ' ++',
+      ' --',
+      '++ --',
+      '-- ++',
+      '+rw+r++r++',
+      '-rw-r--r--',
+      'https://linux.slashdot.org/story/20/04/12/2138205/how-red-hats-new-ceo-handles-life-under-ibm----and-a-global-pandemic'
+    ]
+    ignored.each do |ignore|
+      m = MockMessage.new(ignore, 'user')
+      @plugin.message(m)
+      assert_empty(m.replies, "message should've been ignored: #{ignore.inspect}")
+    end
+
+    m = MockMessage.new('bob++', 'user')
+    @plugin.message(m)
+    assert_equal('bob now has 1 points!', m.replies.first)
+
+    m = MockMessage.new('bot++', 'user')
+    @plugin.message(m)
+    assert_equal('thanks :)', m.replies.first)
   end
 end