示例#1
0
	def test_multiplication(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("1 * 1")))
		self.assertEqual(ircbot.cmd_calc("1 * 1").value, "1")
		self.assertTrue(state.is_done(ircbot.cmd_calc("-1 * 1")))
		self.assertEqual(ircbot.cmd_calc("-1 * 1").value, "-1")
		self.assertTrue(state.is_done(ircbot.cmd_calc("0.1 * 0.1")))
		self.assertEqual(ircbot.cmd_calc("0.1 * 0.1").value, "0.01")
示例#2
0
	def test_division(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("1 / 1")))
		self.assertEqual(ircbot.cmd_calc("1 / 1").value, "1")
		self.assertTrue(state.is_done(ircbot.cmd_calc("1 / 2")))
		self.assertEqual(ircbot.cmd_calc("1 / 2").value, "0")
		self.assertTrue(state.is_done(ircbot.cmd_calc("1.0 / 2")))
		self.assertEqual(ircbot.cmd_calc("1.0 / 2").value, "0.5")
示例#3
0
	def test_addition(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("1 + 1")))
		self.assertEqual(ircbot.cmd_calc("1 + 1").value, "2")
		self.assertTrue(state.is_done(ircbot.cmd_calc("-1 + 1")))
		self.assertEqual(ircbot.cmd_calc("-1 + 1").value, "0")
		self.assertTrue(state.is_done(ircbot.cmd_calc("0.5 + 0.5")))
		self.assertEqual(ircbot.cmd_calc("0.5 + 0.5").value, "1.0")
示例#4
0
	def test_subtraction(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("1 - 1")))
		self.assertEqual(ircbot.cmd_calc("1 - 1").value, "0")
		self.assertTrue(state.is_done(ircbot.cmd_calc("-1 - 1")))
		self.assertEqual(ircbot.cmd_calc("-1 - 1").value, "-2")
		self.assertTrue(state.is_done(ircbot.cmd_calc("0.6 - 0.5")))
		self.assertEqual(ircbot.cmd_calc("0.6 - 0.5").value, "0.1")
示例#5
0
def parse(msg):
	"""
	Parses given input.

	@param msg: input message to parse
	@type msg: str
	@return: return message processed with associated commands and filters
	@rtype: str
	"""
	try:
		cmd, args = msg.split(" ", 1)
	except ValueError:
		cmd, args = msg.rstrip(), ""

	if cmd in COMMANDS:
		ret = COMMANDS[cmd](args)

		if state.is_done(ret):
			return ret.value
		elif state.is_next(ret):
			pass
		else:
			raise Exception("Illegal state of command.")

	for filter in FILTERS:
		ret = filter(msg)

		if state.is_done(ret):
			return ret.value

		if state.is_replace(ret):
			msg = ret.value

	return msg
示例#6
0
	def test_custom(self):
		ircbot.WORDCOUNT = 5
		self.assertEqual(ircbot.WORDCOUNT, 5)
		self.assertTrue(state.is_done(ircbot.cmd_word_count()))
		self.assertEqual(ircbot.cmd_word_count(None).value, 'Actual word count is ' + str(ircbot.WORDCOUNT) + ' words.')
示例#7
0
	def test_correct_parenthesis(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("2 * (1 + 2)")))
		self.assertEqual(ircbot.cmd_calc("2 * (1 + 2)").value, "6")
示例#8
0
	def test_single_negative_number_float(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("-1.0")))
		self.assertEqual(ircbot.cmd_calc("-1.0").value, "-1.0")
示例#9
0
	def test_not_state(self):
		self.assertFalse(state.is_done(object()))
示例#10
0
	def test_not_done(self):
		self.assertFalse(state.is_done(state.replace(None)))
		self.assertFalse(state.is_done(state.next(None)))
示例#11
0
	def test_done(self):
		self.assertTrue(state.is_done(state.done(None)))
示例#12
0
	def test_single_positive_number(self):
		self.assertTrue(state.is_done(ircbot.cmd_calc("1")))
		self.assertEquals(ircbot.cmd_calc("1").value, "1")
示例#13
0
	def test_default(self):
		self.assertTrue(state.is_done(ircbot.cmd_karma('foo')))
		self.assertEqual(ircbot.cmd_karma('foo').value, "'foo' has no karma.")
		ircbot.KARMA = { 'foo': 5 }
		self.assertTrue(state.is_done(ircbot.cmd_karma('foo')))
		self.assertEqual(ircbot.cmd_karma('foo').value, "'foo' has 5 points of karma.")
示例#14
0
	def test_minus_minus(self):
		self.assertTrue(state.is_done(ircbot.f_karma('bar--')))
		self.assertEqual(ircbot.KARMA['bar'], -1)
示例#15
0
	def test_plus_plus(self):
		self.assertTrue(state.is_done(ircbot.f_karma('foo++')))
		self.assertEqual(ircbot.KARMA['foo'], 1)