Example #1
0
    def test_singleOr(self):
        """
        Test code generation for a sequence of alternatives.
        """

        x1 = t.Or([t.Exactly("x")])
        x = t.Exactly("x")
        self.assertEqual(writePython(x, ""), writePython(x1, ""))
Example #2
0
 def test_doubleOr(self):
     xy = t.Or([t.Exactly("x"),
                t.Exactly("y")])
     self.assertEqual(writeBytecode(xy),
                      [t.Choice(3),
                       t.Match('x'),
                       t.Commit(2),
                       t.Match('y')])
Example #3
0
    def test_or(self):
        """
        Test code generation for a sequence of alternatives.
        """

        xy = t.Or([t.Exactly("x"), t.Exactly("y")])
        self.assertEqual(
            writePython(xy, ""),
            dd("""
                            def _G_or_1():
                                _G_exactly_2, lastError = self.exactly('x')
                                self.considerError(lastError, None)
                                return (_G_exactly_2, self.currentError)
                            def _G_or_3():
                                _G_exactly_4, lastError = self.exactly('y')
                                self.considerError(lastError, None)
                                return (_G_exactly_4, self.currentError)
                            _G_or_5, lastError = self._or([_G_or_1, _G_or_3])
                            self.considerError(lastError, None)
                            _G_or_5
                            """))
 def test_singleOr(self):
     x1 = t.Or([t.Exactly("x")])
     x = t.Exactly("x")
     self.assertEqual(writeBytecode(x1), writeBytecode(x))