def test_exactlyFail(self): """ L{OMetaBase.rule_exactly} raises L{_MaybeParseError} when the requested item doesn't match the input. The error contains info on what was expected and the position. """ data = "foo" o = OMetaBase(data) try: o.rule_exactly("g") except _MaybeParseError, e: self.assertEquals(e[1], expected(None, "g")) self.assertEquals(e[0], 0)
def test_exactlyFail(self): """ L{OMetaBase.rule_exactly} raises L{_MaybeParseError} when the requested item doesn't match the input. The error contains info on what was expected and the position. """ data = "foo" o = OMetaBase(data) try: o.rule_exactly("g") except _MaybeParseError as e: self.assertEqual(e[1], expected(None, "g")) self.assertEqual(e[0], 0) else: self.fail('_MaybeParseError not raised')
def test_many(self): """ L{OMetaBase.many} returns a list of parsed values and the error that caused the end of the loop. """ data = "ooops" o = OMetaBase(data) self.assertEqual(o.many(lambda: o.rule_exactly('o')), (['o'] * 3, ParseError(3, expected(None, 'o'))))
def test_many(self): """ L{OMetaBase.many} returns a list of parsed values and the error that caused the end of the loop. """ data = "ooops" o = OMetaBase(data) self.assertEqual(o.many(lambda: o.rule_exactly('o')), (['o'] * 3, _MaybeParseError(3, expected(None, 'o'))))
def test_exactly(self): """ L{OMetaBase.rule_exactly} returns the requested item from the input string along with its position, if it's there. """ data = "foo" o = OMetaBase(data) v, e = o.rule_exactly("f") self.assertEqual(v, "f") self.assertEqual(e[0], 0)