From 32de2b06db501c7de81678bce8e3e0c3e63d340c Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Tue, 22 Jun 2021 22:30:36 -0400 Subject: New upstream version 1.18.0. --- test/test_util.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/test_util.py') diff --git a/test/test_util.py b/test/test_util.py index e2f5084..d90d5ad 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -493,6 +493,30 @@ class TestOther(unittest.TestCase): def test_noop(self): self.assertEqual(util.noop(), None) + def test_compile_expression(self): + expr = util.compile_expression("1 + 2 * 3") + self.assertEqual(expr(), 7) + self.assertEqual(expr({"a": 1, "b": 2, "c": 3}), 7) + self.assertEqual(expr({"a": 9, "b": 9, "c": 9}), 7) + + expr = util.compile_expression("a + b * c") + self.assertEqual(expr({"a": 1, "b": 2, "c": 3}), 7) + self.assertEqual(expr({"a": 9, "b": 9, "c": 9}), 90) + + with self.assertRaises(NameError): + expr() + with self.assertRaises(NameError): + expr({"a": 2}) + + with self.assertRaises(SyntaxError): + util.compile_expression("") + with self.assertRaises(SyntaxError): + util.compile_expression("x++") + + expr = util.compile_expression("1 and abort()") + with self.assertRaises(exception.StopExtraction): + expr() + def test_generate_token(self): tokens = set() for _ in range(100): -- cgit v1.2.3