mirror of https://github.com/Mikaela/Limnoria.git
Fixed some bugs, tested some more and fixed those two. Boomshakalaka!
This commit is contained in:
parent
473ce16776
commit
bb9cb5d67c
|
@ -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,9 +106,19 @@ class OptionList(object):
|
|||
elif token == '(':
|
||||
ret.append(self._insideParens(lexer))
|
||||
elif token == ')':
|
||||
raise SyntaxError, 'Spurious ")"'
|
||||
else:
|
||||
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
|
||||
|
||||
def tokenize(s):
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue