def test_consume_existing(self): """Test the consume method when the token exists.""" parser = SimpleParser("Hello, World!") self.assertEqual(parser.consume("\w+"), "Hello") self.assertEqual(parser.consume(", "), ", ") self.assertEqual(parser.consume("\w+"), "World") self.assertEqual(parser.consume("!"), "!")
def test_consume_missing(self): """Test the consume method when the token does not exist.""" parser = SimpleParser("Hello, World!") with self.assertRaises(Exception): parser.consume("\d+")
def test_peek_missing(self): """Test the peek method when the token does not exist.""" parser = SimpleParser("Hello, World!") self.assertEqual(parser.peek("\d+"), "")
def test_peek_existing(self): """Test the peek method when the token exists.""" parser = SimpleParser("Hello, World!") self.assertEqual(parser.peek("\w+"), "Hello")
def consume(self, regexp): token = SimpleParser.consume(self, regexp) self.buffer = self.buffer.lstrip() return token
def __init__(self, dds): SimpleParser.__init__(self, dds, re.IGNORECASE) self.dds = dds
def __init__(self, das, dataset): SimpleParser.__init__(self, das, re.IGNORECASE | re.VERBOSE | re.DOTALL) self.das = das self.dataset = dataset