def test_parse_failure(self): """Make sure ``parse()`` fails when it doesn't recognize all the way to the end.""" expr = OneOrMore(Literal('a', name='lit'), name='more') text = 'aab' eq_(expr.parse(text), None)
def test_one_or_more(self): len_eq(OneOrMore(Literal('b')).match('b'), 1) # one len_eq(OneOrMore(Literal('b')).match('bbb'), 3) # more len_eq(OneOrMore(Literal('b'), min=3).match('bbb'), 3) # with custom min; success len_eq(OneOrMore(Literal('b'), min=3).match('bb'), None) # with custom min; failure len_eq(OneOrMore(Regex('^')).match('bb'), 0) # attempt infinite loop
def test_one_or_more_one(self): """Test the 1 case of ``OneOrMore``; it should return a node with a child.""" expr = OneOrMore(Literal('a', name='lit'), name='one') text = 'a' eq_(expr.match(text), Node('one', text, 0, 1, children=[ Node('lit', text, 0, 1)]))