fix the parser to account for comments with other important tokens
This commit is contained in:
@@ -325,6 +325,12 @@ class DiceRoller(object):
|
||||
# Parse a comment.
|
||||
|
||||
'''comment : TEXT
|
||||
| DIFFICULTYSTR
|
||||
| TASKSTR
|
||||
| ATTACKSTR
|
||||
| MIGHT_STR
|
||||
| SPEED_STR
|
||||
| INTELLECT_STR
|
||||
|'''
|
||||
if len(p) == 2:
|
||||
p[0] = p[1]
|
||||
|
||||
@@ -29,6 +29,24 @@ class DiceRollerTestCase(TestCase):
|
||||
self.assertEqual(result, '3 (3[1,1,1,1]), 6 (6[2,2,2,2]), 9 (9[3,3,3,3]), '
|
||||
'12 (12[4,4,4,4]), 15 (15[5,5,5,5]), 18 (18[6,6,6,6])')
|
||||
|
||||
def test_standard_rolls_with_comments(self):
|
||||
"""Test slightly more complex parsers."""
|
||||
with mock.patch('random.randint', return_value=5):
|
||||
result = self.roller.do_roll('1d20 attack')
|
||||
self.assertEqual(result, '5 attack (5[5])')
|
||||
|
||||
with mock.patch('random.randint', return_value=5):
|
||||
result = self.roller.do_roll('1d20 task')
|
||||
self.assertEqual(result, '5 task (5[5])')
|
||||
|
||||
with mock.patch('random.randint', return_value=5):
|
||||
result = self.roller.do_roll('1d20 task check')
|
||||
self.assertEqual(result, '5 task check (5[5])')
|
||||
|
||||
with mock.patch('random.randint', return_value=5):
|
||||
result = self.roller.do_roll('1d20 this is a difficulty check')
|
||||
self.assertEqual(result, '5 this is a difficulty check (5[5])')
|
||||
|
||||
def test_cypher_rolls(self):
|
||||
"""Roll a variety of cypher rolls."""
|
||||
with mock.patch('random.SystemRandom.randint', return_value=5):
|
||||
|
||||
Reference in New Issue
Block a user