def test__parser__lexer_lex_match(caplog): """Test the RepeatedMultiMatcher.""" matchers = [ StringMatcher("dot", ".", CodeSegment), RegexMatcher("test", r"#[^#]*#", CodeSegment), ] with caplog.at_level(logging.DEBUG): res = Lexer.lex_match("..#..#..#", matchers) assert res.forward_string == "#" # Should match right up to the final element assert len(res.elements) == 5 assert res.elements[2].raw == "#..#"
def test__parser__lexer_multimatcher(caplog): """Test the RepeatedMultiMatcher.""" matcher = RepeatedMultiMatcher( SingletonMatcher("dot", ".", RawSegment.make(".", name="dot", is_code=True)), RegexMatcher("test", r"#[^#]*#", RawSegment.make("test", name="test")), ) start_pos = FilePositionMarker.from_fresh() with caplog.at_level(logging.DEBUG): res = matcher.match("..#..#..#", start_pos) assert res.new_string == "#" # Should match right up to the final element assert res.new_pos == start_pos.advance_by("..#..#..") assert len(res.segments) == 5 assert res.segments[2].raw == "#..#"
def test__parser__lexer_regex(raw, reg, res, caplog): """Test the RegexMatcher.""" matcher = RegexMatcher("test", reg, RawSegment.make("test", name="test")) with caplog.at_level(logging.DEBUG): assert_matches(raw, matcher, res)