Ejemplo n.º 1
0
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 == "#..#"
Ejemplo n.º 2
0
 def make_whitespace(cls, raw, pos_marker):
     """Make a whitespace segment."""
     WhitespaceSegment = RawSegment.make(" ",
                                         name="whitespace",
                                         type="whitespace",
                                         is_whitespace=True)
     return WhitespaceSegment(raw=raw, pos_marker=pos_marker)
Ejemplo n.º 3
0
def test__parser__lexer_singleton(raw, res):
    """Test the SingletonMatcher."""
    matcher = SingletonMatcher("dot", ".",
                               RawSegment.make(".", name="dot", is_code=True))
    assert_matches(raw, matcher, res)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 def make_newline(cls, pos_marker, raw=None):
     """Make a newline segment."""
     # Default the newline to \n
     raw = raw or "\n"
     nls = RawSegment.make("\n", name="newline", type="newline")
     return nls(raw=raw, pos_marker=pos_marker)