Ejemplo n.º 1
0
    def test_predSuccess(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        v, e = o.pred(lambda: (True, _MaybeParseError(0, None)))
        self.assertEqual((v, e), (True, _MaybeParseError(0, None)))
Ejemplo n.º 2
0
    def test_predSuccess(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        v, e = o.pred(lambda: (True, _MaybeParseError(0, None)))
        self.assertEqual((v, e), (True, _MaybeParseError(0, None)))
Ejemplo n.º 3
0
    def test_predFailure(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        try:
            o.pred(lambda: (False, _MaybeParseError(0, None)))
        except _MaybeParseError, e:
            self.assertEqual(e, _MaybeParseError(0, None))
Ejemplo n.º 4
0
    def test_predFailure(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        try:
            o.pred(lambda: (False, _MaybeParseError(0, None)))
        except _MaybeParseError as e:
            self.assertEqual(e, _MaybeParseError(0, None))
        else:
            self.fail('_MaybeParseError not raised')
Ejemplo n.º 5
0
 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{_MaybeParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     try:
         o.rule_end()
     except _MaybeParseError as e:
         self.assertEqual(e, _MaybeParseError(1, None))
     else:
         self.fail('_MaybeParseError not raised')
     o.many(o.rule_anything)
     self.assertEqual(o.rule_end(), (True, _MaybeParseError(3, None)))
Ejemplo n.º 6
0
 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{_MaybeParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     try:
         o.rule_end()
     except _MaybeParseError as e:
         self.assertEqual(e, _MaybeParseError(1, None))
     else:
         self.fail('_MaybeParseError not raised')
     o.many(o.rule_anything)
     self.assertEqual(o.rule_end(), (True, _MaybeParseError(3, None)))
Ejemplo n.º 7
0
 def test_consumed_by(self):
     """
     L{OMetaBase.consumed_by} return the full matched string, not each matched parts
     """
     o = OMetaBase("aax")
     v, e = o.consumed_by(lambda: o.many(lambda: o.exactly("a")))
     self.assertEqual((v, e), ("aa", _MaybeParseError(2, [('expected', None, 'a')])))
Ejemplo n.º 8
0
    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'))))
Ejemplo n.º 9
0
    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'))))
Ejemplo n.º 10
0
 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{_MaybeParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     try:
         o.rule_end()
     except _MaybeParseError, e:
         self.assertEqual(e, _MaybeParseError(1, None))
Ejemplo n.º 11
0
 def test_digit(self):
     """
     L{OMetaBase.rule_digit} matches digits.
     """
     o = OMetaBase("1a")
     v, e = o.rule_digit()
     self.assertEqual((v, e), ("1", [0, None]))
     try:
         o.rule_digit()
     except _MaybeParseError, e:
         self.assertEqual(e, _MaybeParseError(1, expected("digit")))
Ejemplo n.º 12
0
    def test_letter(self):
        """
        L{OMetaBase.rule_letter} matches letters.
        """

        o = OMetaBase("a1")
        v, e = o.rule_letter()
        self.assertEqual((v, e), ("a", [0, None]))
        try:
            o.rule_letter()
        except _MaybeParseError, e:
            self.assertEqual(e, _MaybeParseError(1, expected("letter")))
Ejemplo n.º 13
0
 def test_letterOrDigit(self):
     """
     L{OMetaBase.rule_letterOrDigit} matches alphanumerics.
     """
     o = OMetaBase("a1@")
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("a", [0, None]))
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("1", [1, None]))
     try:
         o.rule_letterOrDigit()
     except _MaybeParseError, e:
         self.assertEqual(e, _MaybeParseError(2, expected("letter or digit")))
Ejemplo n.º 14
0
 def test_digit(self):
     """
     L{OMetaBase.rule_digit} matches digits.
     """
     o = OMetaBase("1a")
     v, e = o.rule_digit()
     self.assertEqual((v, e), ("1", [0, None]))
     try:
         o.rule_digit()
     except _MaybeParseError as e:
         self.assertEqual(e, _MaybeParseError(1, expected("digit")))
     else:
         self.fail('_MaybeParseError not raised')
Ejemplo n.º 15
0
    def test_letter(self):
        """
        L{OMetaBase.rule_letter} matches letters.
        """

        o = OMetaBase("a1")
        v, e = o.rule_letter()
        self.assertEqual((v, e), ("a", [0, None]))
        try:
            o.rule_letter()
        except _MaybeParseError as e:
            self.assertEqual(e, _MaybeParseError(1, expected("letter")))
        else:
            self.fail('_MaybeParseError not raised')
Ejemplo n.º 16
0
 def test_letterOrDigit(self):
     """
     L{OMetaBase.rule_letterOrDigit} matches alphanumerics.
     """
     o = OMetaBase("a1@")
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("a", [0, None]))
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("1", [1, None]))
     try:
         o.rule_letterOrDigit()
     except _MaybeParseError as e:
         self.assertEqual(e, _MaybeParseError(2, expected("letter or digit")))
     else:
         self.fail('_MaybeParseError not raised')
Ejemplo n.º 17
0

    def test_end(self):
        """
        L{OMetaBase.rule_end} matches the end of input and raises L{_MaybeParseError}
        if input is left.
        """
        o = OMetaBase("abc")
        try:
            o.rule_end()
        except _MaybeParseError, e:
            self.assertEqual(e, _MaybeParseError(1, None))
        else:
            self.fail('_MaybeParseError not raised')
        o.many(o.rule_anything)
        self.assertEqual(o.rule_end(), (True, _MaybeParseError(3, None)))


    def test_letter(self):
        """
        L{OMetaBase.rule_letter} matches letters.
        """

        o = OMetaBase("a1")
        v, e = o.rule_letter()
        self.assertEqual((v, e), ("a", [0, None]))
        try:
            o.rule_letter()
        except _MaybeParseError, e:
            self.assertEqual(e, _MaybeParseError(1, expected("letter")))
        else: