Exemple #1
0
 def test_it_is_false_when_clause_is_true(self):
     clause = mock.Mock(return_value=True)
     neg = parsing.Neg(clause)
     parser = mock.Mock(**{'_stream.restore_context.return_value': False})
     self.assertFalse(neg(parser))
     parser._stream.save_context.assert_called_once_with()
     parser._stream.restore_context.assert_called_once_with()
Exemple #2
0
 def test_it_is_true_when_clause_is_false(self):
     clause = mock.Mock(return_value=False)
     neg = parsing.Neg(clause)
     parser = mock.Mock()
     self.assertTrue(neg(parser))
     parser._stream.save_context.assert_called_once_with()
     parser._stream.validate_context.assert_called_once_with()
Exemple #3
0
def add_mod(self, seq, mod):
    """Create a tree.{Complement, LookAhead, Neg, Until}"""
    modstr = self.value(mod)
    if modstr == '~':
        seq.parser_tree = parsing.Complement(seq.parser_tree)
    elif modstr == '!!':
        seq.parser_tree = parsing.LookAhead(seq.parser_tree)
    elif modstr == '!':
        seq.parser_tree = parsing.Neg(seq.parser_tree)
    elif modstr == '->':
        seq.parser_tree = parsing.Until(seq.parser_tree)
    return True
Exemple #4
0
 def test_16_Negation(self):
     """
     Basic test for negation !R
     """
     parser = parsing.Parser()
     parser.parsed_stream("==")
     parseTree = \
         parsing.Seq(parsing.Call(parsing.Parser.read_char, '='),
                     parsing.Neg(parsing.Call(
                         parsing.Parser.read_char,
                         '=')))
     res = parseTree(parser)
     self.assertEqual(res, False, "failed to get the correct final value")
     self.assertEqual(parser._stream._cursor._index, 0,
                      "failed to get the correct index after a negation")