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 testDuplicateBranchInAlternative(self): a = builder.makeAlternative( [Terminal("bar"), Terminal("foo"), Terminal("bar"), Null]) b = Alternative([Terminal("bar"), Terminal("foo"), Null]) self.assertEqual(a, b)
def testRestrictionWithLongerException(self): self.rules = [ Rule( "restriction", Restriction(Terminal("base"), Terminal("long exception branch"))) ]
def testRestrictionWithShorterException(self): self.rules = [ Rule( "restriction", Restriction(Terminal("long base branch"), Terminal("exception"))) ]
def testRepetitionWithLongBackwardBranch(self): self.rules = [ Rule( "repetition", Repetition(Terminal("forward"), Terminal("backward branch is longer"))) ]
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 testNull(self): self.rules = [ Rule( "sequence with null", Sequence([ Terminal("space here ->"), Null, Terminal("should be like here ->"), Terminal("foo") ])) ]
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 testTerminal(self): self.rules = [Rule("terminal", Terminal("in a rounded rectangle"))]
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 testCommonTerminalBeforeRepetition(self): a = builder.makeSequence( [Terminal("a"), Repetition(Null, Terminal("a"))]) b = Repetition(Terminal("a"), Null) self.assertEqual(a, b)
def testMultipleSimplifcationSteps(self): a = builder.makeAlternative( [Terminal("bar"), Alternative([Terminal("bar"), Terminal("bar")])]) b = Terminal("bar") self.assertEqual(a, b)
def testAlternativeInAlternative(self): a = builder.makeAlternative( [Terminal("foo"), Alternative([Terminal("bar"), Terminal("baz")])]) b = Alternative([Terminal("foo"), Terminal("bar"), Terminal("baz")]) self.assertEqual(a, b)
def testAlternativeWithOneBranch(self): a = builder.makeAlternative([Terminal("foo")]) b = Terminal("foo") self.assertEqual(a, b)