def testCommonSequenceBeforeRepetition(self): a = builder.makeSequence([ NonTerminal("b"), Terminal("a"), Repetition(Null, Sequence([NonTerminal("b"), Terminal("a")])) ]) b = Repetition(Sequence([NonTerminal("b"), Terminal("a")]), Null) self.assertEqual(a, b)
def testNoCommonNullAfterRepetition(self): a = builder.makeSequence([Repetition(NonTerminal("b"), Null), Terminal("d")]) b = Sequence([Repetition(NonTerminal("b"), Null), Terminal("d")]) self.assertEqual(a, b)
def testCommonRestrictionAfterRepetition(self): a = builder.makeSequence([Repetition(Null, Restriction(Terminal("d"), Terminal("e"))), Restriction(Terminal("d"), Terminal("e"))]) b = Repetition(Restriction(Terminal("d"), Terminal("e")), Null) self.assertEqual(a, b)
def testCommonAlternativeAfterRepetition(self): a = builder.makeSequence([Repetition(Null, Alternative([Terminal("d"), Terminal("e")])), Alternative([Terminal("d"), Terminal("e")])]) b = Repetition(Alternative([Terminal("d"), Terminal("e")]), Null) self.assertEqual(a, b)
def testCommonSequenceAfterRepetition(self): a = builder.makeSequence([Repetition(Null, Sequence([NonTerminal("b"), Terminal("a")])), NonTerminal("b"), Terminal("a")]) b = Repetition(Sequence([NonTerminal("b"), Terminal("a")]), Null) self.assertEqual(a, b)
def testCommonNonTerminalBeforeRepetition(self): a = builder.makeSequence([NonTerminal("a"), Repetition(Null, NonTerminal("a"))]) b = Repetition(NonTerminal("a"), Null) self.assertEqual(a, b)
def testNullInSequence(self): a = builder.makeSequence([NonTerminal("foo"), Null, Terminal("bar"), Null, Terminal("baz")]) b = Sequence([NonTerminal("foo"), Terminal("bar"), Terminal("baz")]) self.assertEqual(a, b)
def testSequenceWithOneElement(self): a = builder.makeSequence([NonTerminal("foo")]) b = NonTerminal("foo") self.assertEqual(a, b)
def testEmptySequence(self): a = builder.makeSequence([]) b = Null self.assertEqual(a, b)
def testNoCommonNullAfterRepetition(self): a = builder.makeSequence( [Repetition(NonTerminal("b"), Null), Terminal("d")]) b = Sequence([Repetition(NonTerminal("b"), Null), Terminal("d")]) self.assertEqual(a, b)
def testCommonNonTerminalAfterRepetition(self): a = builder.makeSequence( [Repetition(Null, NonTerminal("a")), NonTerminal("a")]) b = Repetition(NonTerminal("a"), Null) self.assertEqual(a, b)
def testSequenceInSequence(self): a = builder.makeSequence( [NonTerminal("foo"), Sequence([Terminal("bar"), Terminal("baz")])]) b = Sequence([NonTerminal("foo"), Terminal("bar"), Terminal("baz")]) self.assertEqual(a, b)