From 07a397f63f0c7dc7f53830a57ce9048cfd9efb53 Mon Sep 17 00:00:00 2001 From: Matthias Hecker Date: Mon, 6 Apr 2020 21:08:55 +0200 Subject: plugin(points): +/- must come after, closes #34 This modifies the karma/points plugin to ignore increment/ decrement suffixes. `--SOMETHING` is more trouble than its worth, people will write --NAME as a signature, or paste a command line argument, e.g. `ls --sort time` which causes issues. I also added tests for the points plugin, the plan is to make the plugin testing easier more "rubionic" --- test/mock.rb | 5 +++-- test/plugins/test_points.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mock.rb b/test/mock.rb index f1ce92dd..511daaba 100644 --- a/test/mock.rb +++ b/test/mock.rb @@ -1,6 +1,7 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') $:.unshift File.join(File.dirname(__FILE__), '..') - +#require 'rbot/logger' +#Irc::Bot::LoggerManager.instance.set_level(5) module Irc class Bot @@ -55,7 +56,7 @@ class MockMessage def initialize(message='', source='user') @message = message @sourcenick = source - @channel = Irc::Channel.new('#test', '', [], server: nil) + @channel = Irc::Channel.new('#test', '', ['bob'], server: nil) @replies = [] end diff --git a/test/plugins/test_points.rb b/test/plugins/test_points.rb index f1a7479d..83018e2e 100644 --- a/test/plugins/test_points.rb +++ b/test/plugins/test_points.rb @@ -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,31 @@ 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) + + ignored = [ + '++alice', + '--alice', + 'something something --github', + 'ls --sort time', + '-- foo', + '++ foo', + ] + 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_include(MockBot.new.lang.strings['thanks'], m.replies.first) end end -- cgit v1.2.3