Add test to verify a single period is not accepted as input
This commit is contained in:
@@ -182,7 +182,7 @@ def evaluator(variables, functions, string, cs=False):
|
||||
|
||||
number_part = Word(nums)
|
||||
|
||||
# 0.33 or 7 or .34
|
||||
# 0.33 or 7 or .34 or 16.
|
||||
inner_number = (number_part + Optional("." + Optional(number_part))) | ("." + number_part)
|
||||
|
||||
# 0.33k or -17
|
||||
|
||||
@@ -37,6 +37,13 @@ class EvaluatorTest(unittest.TestCase):
|
||||
self.assertEqual(easy_eval("-3.14"), -3.14)
|
||||
self.assertEqual(easy_eval("-.618033989"), -0.618033989)
|
||||
|
||||
def test_period(self):
|
||||
"""
|
||||
The string '.' should not evaluate to anything.
|
||||
"""
|
||||
self.assertRaises(ParseException, calc.evaluator, {}, {}, '.')
|
||||
self.assertRaises(ParseException, calc.evaluator, {}, {}, '1+.')
|
||||
|
||||
def test_trailing_period(self):
|
||||
"""
|
||||
Test that things like '4.' will be 4 and not throw an error
|
||||
|
||||
Reference in New Issue
Block a user