def test_literal(self): rx = Literal('abc') rx.config.clear().compile_to_nfa(force=True) matcher = rx.get_match_null() assert isinstance(matcher.matcher, NfaRegexp), matcher.matcher results = list(matcher('abcd')) assert results == [(['abc'], 'd')], results rx = Literal('abc') >> (lambda x: x+'e') rx.config.clear().compose_transforms().compile_to_nfa(force=True) matcher = rx.get_match_null() results = list(matcher('abcd')) assert results == [(['abce'], 'd')], results #print(repr(matcher.matcher)) assert isinstance(matcher.matcher, NfaRegexp), matcher.matcher
def test_complex(self): #basicConfig(level=DEBUG) rx = Literal('foo') | (Literal('ba') + Any('a')[1:,...]) rx.config.compile_to_nfa().no_full_first_match() matcher = rx.get_match_null() results = list(matcher('foo')) assert results == [(['foo'], '')], results results = list(matcher('baaaaax')) assert results == [(['baaaaa'], 'x'), (['baaaa'], 'ax'), (['baaa'], 'aax'), (['baa'], 'aaax')], results results = list(matcher('ba')) assert results == [], results assert isinstance(matcher.matcher, NfaRegexp), matcher.matcher