Esempio n. 1
0
def test_result_hides_empty_matches():
    result = Result(
        Matches("HELLO",
                Context(context=1),
                pattern="NO_MATCH",
                only_matched=True))
    assert str(result) == ""
Esempio n. 2
0
def test_context():
    matches = Matches(
        """A
    B
    C
    D
    A
    B
    C
    D""",
        Context(context=2),
        "A",
        number_lines=True,
    )

    assert set(matches.matching_lines()) == {0, 1, 2, 3, 4, 5, 6}
Esempio n. 3
0
def test_context_supplied_as_an_int():
    matches = Matches(
        """A
    B
    C
    D
    A
    B
    C
    D""",
        context=2,
        pattern="A",
        number_lines=True,
    )

    assert set(matches.matching_lines()) == {0, 1, 2, 3, 4, 5, 6}
Esempio n. 4
0
def test_only_matched_with_context():
    matches = Matches("""ABCDE
FFF""",
                      Context(context=1),
                      "B.D",
                      only_matched=True)
    assert tuple(matches) == ("BCD", "")
Esempio n. 5
0
def test_after():
    matches = Matches(
        """A
B
C
D
A
B
C
D""",
        Context(after=1),
        "A",
        number_lines=True,
    )

    assert set(matches.matching_lines()) == {0, 1, 4, 5}
Esempio n. 6
0
def test_before():
    matches = Matches(
        """A
B
C
D
A
B
C
D""",
        Context(before=1),
        "A",
        number_lines=True,
    )

    assert set(matches.matching_lines()) == {0, 4, 3}
Esempio n. 7
0
def test_context_is_not_colored():
    matches = Matches(
        """ABCDE
MEOW""",
        Context(after=1),
        "B.D",
        color="red",
    )
    assert tuple(matches) == (color_str("ABCDE", "red"), "MEOW")
Esempio n. 8
0
def test_invert_match():
    matches = Matches(
        """Hello
HeLLO
HOW LOW
HALLOW""",
        Context(),
        Pattern("e", invert_match=True),
    )

    assert tuple(matches) == ("HOW LOW", "HALLOW")
Esempio n. 9
0
def test_ignore_case():
    matches = Matches(
        """Hello
HELLO
HOW LOW
HALLOW""",
        Context(),
        Pattern("e", ignore_case=True),
    )

    assert tuple(matches) == ("Hello", "HELLO")
Esempio n. 10
0
def test_words_only():
    matches = Matches(
        """Hello
Die today
Yes hello bye
effo
""",
        Context(),
        Pattern("e..o", words_only=True),
    )

    assert tuple(matches) == ("effo",)
Esempio n. 11
0
def test_sanity():
    matches = Matches(
        """A
B
C
D
A
B
C
D""",
        Context(),
        "A",
    )

    assert tuple(matches) == ("A", "A")
Esempio n. 12
0
def test_sanity():
    matches = Matches(
        """A
1
C
4
A
6
7
D""",
        Context(),
        Pattern("\d"),
    )

    assert tuple(matches) == ("1", "4", "6", "7")
Esempio n. 13
0
def test_line_numbering():
    matches = Matches(
        """A
B
C
D
A
B
C
D""",
        Context(),
        "A",
        number_lines=True,
    )

    assert tuple(matches) == ("1: A", "5: A")
Esempio n. 14
0
def test_color():
    matches = Matches("ABCDE", Context(), "B.D", color="red")
    assert tuple(matches) == (color_str("ABCDE", "red"), )
Esempio n. 15
0
def test_only_matched():
    matches = Matches("ABCDE", Context(), "B.D", only_matched=True)
    assert tuple(matches) == ("BCD", )
Esempio n. 16
0
def test_zero_based():
    matches = Matches("A", Context(), "A", zero_based=True, number_lines=True)
    assert tuple(matches) == ("0: A", )