Ejemplo n.º 1
0
 def test_constant_statements(self):
     parser = ParserFactory(fixtures.constant_statements)
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(), [
         [(tok.INTEGER, 444), (tok.AND, 'AND'), (tok.BOOL, True)],
         (tok.OR, 'OR'),
         (tok.STRING, 'yes'),
     ])
Ejemplo n.º 2
0
 def test_implicit_boolean_cast(self):
     parser = ParserFactory(fixtures.implicit_boolean_cast)
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(), [
         (tok.ID, 'Z'),
         (tok.OR, 'OR'),
         [(tok.ID, 'X'), (tok.AND, 'AND'), (tok.ID, 'Y')],
     ])
Ejemplo n.º 3
0
 def test_operators_precedence(self):
     parser = ParserFactory(fixtures.operators_precedence)
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(), [
         [(tok.ID, 'X'), (tok.LT, '<'), (tok.FLOAT, 5.15)],
         (tok.OR, 'OR'),
         [
             [(tok.ID, 'X'), (tok.GT, '>'), (tok.INTEGER, 10)],
             (tok.AND, 'AND'),
             [(tok.ID, 'Y'), (tok.EQ, '=='), (tok.STRING, 'eligible')],
         ],
     ])
Ejemplo n.º 4
0
 def test_parser(self):
     parser = ParserFactory(fixtures.simple_example)
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(), [[[(tok.ID, 'X'),
                                                    (tok.GT, '>'),
                                                    (tok.INTEGER, 42)],
                                                   (tok.AND, 'AND'),
                                                   [(tok.ID, 'Y'),
                                                    (tok.NE, '!='),
                                                    (tok.BOOL, True)]],
                                                  (tok.OR, 'OR'),
                                                  [(tok.ID, 'Z'),
                                                   (tok.EQ, '=='),
                                                   (tok.STRING, 'yes')]])
Ejemplo n.º 5
0
 def test_parsing_parentheses(self):
     parser = ParserFactory(fixtures.parentheses)
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(), [
         [
             [(tok.ID, 'X'), (tok.LTE, '<='), (tok.INTEGER, 42)],
             (tok.OR, 'OR'),
             [(tok.ID, 'Y'), (tok.EQ, '=='), (tok.STRING, 'yes')],
         ],
         (tok.AND, 'AND'),
         [[(tok.ID, 'Y'), (tok.EQ, '=='), (tok.STRING, 'no')],
          (tok.OR, 'OR'), [(tok.ID, 'X'), (tok.GTE, '>='),
                           (tok.INTEGER, 17)]],
     ])
Ejemplo n.º 6
0
 def test_not_nested(self):
     parser = ParserFactory('not not x')
     abstract_tree = parser.parse()
     self.assertEqual(abstract_tree.tree_repr(),
                      [(tok.NOT, 'NOT'), [(tok.NOT, 'NOT'), (tok.ID, 'X')]])
Ejemplo n.º 7
0
 def test_empty_expression(self):
     parser = ParserFactory('')
     abstract_tree = parser.parse()
     self.assertEqual(['noop'], abstract_tree.tree_repr())
Ejemplo n.º 8
0
 def test_parser_raises_on_invalid_ast(self):
     parser = ParserFactory("x >>= f")
     with self.assertRaises(BambooleanParserError):
         parser.parse()