def testRuleNamesWithAscentAndDescent(self): self.rules = [ Rule("aaaaa", NonTerminal("ascent and descent")), Rule("ppppp", NonTerminal("should")), Rule("ddddd", NonTerminal("look")), Rule("dddpp", NonTerminal("right")) ]
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 testRepetitionWithLongForwardBranch(self): self.rules = [ Rule( "repetition", Repetition(NonTerminal("forward branch is longer"), NonTerminal("backward"))) ]
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 testSequence(self): self.rules = [ Rule( "sequence", Sequence([ NonTerminal("with"), NonTerminal("one"), NonTerminal("branch") ])) ]
def testAlternative(self): self.rules = [ Rule( "alternative", Alternative([ NonTerminal("with"), NonTerminal("several"), NonTerminal("branches") ])) ]
def testImbricatedRepetitions(self): self.rules = [ Rule( "repetition", Repetition( Repetition(NonTerminal("forward 1"), NonTerminal("backward 1")), Repetition(NonTerminal("forward 2"), NonTerminal("backward 2")))) ]
def testBackwardAlternative(self): self.rules = [ Rule( "repetition", Repetition( NonTerminal("forward"), Alternative([ NonTerminal("foo"), NonTerminal("bar"), NonTerminal("baz") ]))) ]
def testAlternativeWithOneBranch(self): self.rules = [ Rule("alternative", Alternative([NonTerminal("with one branch")])) ]
def testLongRuleName(self): self.rules = [ Rule("this long rule name should not be truncated", NonTerminal("foo")), ]
def testNonTerminal(self): self.rules = [Rule("non terminal", NonTerminal("in a 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 testCommonNonTerminalBeforeRepetition(self): a = builder.makeSequence( [NonTerminal("a"), Repetition(Null, NonTerminal("a"))]) b = Repetition(NonTerminal("a"), Null) self.assertEqual(a, b)
def testSequenceWithOneElement(self): a = builder.makeSequence([NonTerminal("foo")]) b = NonTerminal("foo") self.assertEqual(a, b)