def test_no_flatten_and(self): matcher = And('a', Join(And('b', 'c'))) matcher.config.clear().flatten() parser = matcher.get_parse() text = str(parser.matcher) assert text == "And(Literal, Transform)", text result = parser('abcd') assert result == ['a', 'bc'], result
def test_flatten_and_transform(self): matcher = Join(And('a', And('b', 'c'))) matcher.config.clear().flatten() parser = matcher.get_parse() text = sub('<.*>', '<>', str(parser.matcher)) assert text == "Transform(And, TransformationWrapper(<>))", text result = parser('abcd') assert result == ['abc'], result
def test_add(self): rx = Add(And(Any('a'), Any('b'))) rx.config.clear().compile_to_nfa(force=True) matcher = rx.get_match_null() results = list(matcher('abq')) assert results == [(['ab'], 'q')], results assert isinstance(matcher.matcher, NfaRegexp), matcher.matcher
def test_replace(self): #basicConfig(level=DEBUG) matcher = And('a', 'b') matcher.config.clear().direct_eval() parser = matcher.get_parse() text = str(parser.matcher) assert "AndNoTrampoline(Literal, Literal)" == text, text result = parser('ab') assert result == ['a', 'b'], result
def _assert_string(self, separator, expecteds, streams=STREAMS_3): with separator: parser = And(Optional('a') & Optional('b') & 'c', Eos()) ok = True parser.config.no_full_first_match() for (stream, expected) in zip(streams, expecteds): parsed = parser.parse_string(stream) is not None if PRINT: print('{0!r:9} : {1!r:5} {2!r:5}' .format(stream, parsed, parsed == expected)) ok = ok and (parsed == expected) assert ok