Fixed some bugs, tested some more and fixed those two. Boomshakalaka!

This commit is contained in:
Jeremy Fincher 2003-11-10 22:43:19 +00:00
parent 473ce16776
commit bb9cb5d67c
2 changed files with 32 additions and 11 deletions

View File

@ -77,10 +77,10 @@ class OptionList(object):
while True:
token = lexer.get_token()
if not token:
raise SyntaxError, 'Missing ")"'
return '(%s' % ''.join(ret) #)
elif token == ')':
if len(ret) > 1:
return ret
return [x for x in ret if x != '|']
elif len(ret) == 1:
return '(%s)' % ret[0]
else:
@ -88,7 +88,7 @@ class OptionList(object):
elif token == '(':
ret.append(self._insideParens(lexer))
elif token == '|':
continue
ret.append(token)
else:
ret.append(token)
@ -106,7 +106,17 @@ class OptionList(object):
elif token == '(':
ret.append(self._insideParens(lexer))
elif token == ')':
raise SyntaxError, 'Spurious ")"'
if ret: #(
ret[-1] += ')'
else: #(
ret.append(')')
elif token == '|':
ret.append(token)
else:
if ret and ret[-1] == '|':
pipe = ret.pop()
first = ret.pop()
ret.append(pipe.join([first, token]))
else:
ret.append(token)
return ret

View File

@ -38,18 +38,29 @@ except ImportError:
if sqlite is not None:
MoobotFactoids = Owner.loadPluginModule('MoobotFactoids')
MF = MoobotFactoids
class OptionListTestCase(unittest.TestCase):
def testEmptyParens(self):
self.assertEqual(MoobotFactoids.tokenize('()'), ['()'])
self.assertEqual(MF.tokenize('()'), ['()'])
def testNoBarParens(self):
self.assertEqual(MoobotFactoids.tokenize('(foo)'), ['(foo)'])
self.assertEqual(MF.tokenize('(foo)'), ['(foo)'])
def testDanglingParens(self):
self.assertEqual(MoobotFactoids.tokenize('(foo'), ['(foo'])
self.assertEqual(MoobotFactoids.tokenize('(foo|bar'),['(foo|bar'])
self.assertEqual(MoobotFactoids.tokenize('foo)'), ['foo)'])
self.assertEqual(MoobotFactoids.tokenize('foo|bar)'),['foo|bar)'])
self.assertEqual(MF.tokenize('(foo'), ['(foo'])
self.assertEqual(MF.tokenize('(foo|bar'),['(foo|bar'])
self.assertEqual(MF.tokenize('foo)'), ['foo)'])
self.assertEqual(MF.tokenize('foo|bar)'),['foo|bar)'])
def testPipesOutsideParens(self):
self.assertEqual(MF.tokenize('1|2'), ['1|2'])
def testStandardBehavior(self):
self.assertEqual(MF.tokenize('(foo|bar)'), [['foo', 'bar']])
self.assertEqual(MF.tokenize('(foo|bar|baz)'),
[['foo','bar','baz']])
self.assertEqual(MF.tokenize('(foo|(bar|baz))'),
[['foo', ['bar', 'baz']]])
class FactoidsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('MoobotFactoids', 'User', 'Utilities')