def test_result_hides_empty_matches(): result = Result( Matches("HELLO", Context(context=1), pattern="NO_MATCH", only_matched=True)) assert str(result) == ""
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}
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}
def test_only_matched_with_context(): matches = Matches("""ABCDE FFF""", Context(context=1), "B.D", only_matched=True) assert tuple(matches) == ("BCD", "")
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}
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}
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")
def test_invert_match(): matches = Matches( """Hello HeLLO HOW LOW HALLOW""", Context(), Pattern("e", invert_match=True), ) assert tuple(matches) == ("HOW LOW", "HALLOW")
def test_ignore_case(): matches = Matches( """Hello HELLO HOW LOW HALLOW""", Context(), Pattern("e", ignore_case=True), ) assert tuple(matches) == ("Hello", "HELLO")
def test_words_only(): matches = Matches( """Hello Die today Yes hello bye effo """, Context(), Pattern("e..o", words_only=True), ) assert tuple(matches) == ("effo",)
def test_sanity(): matches = Matches( """A B C D A B C D""", Context(), "A", ) assert tuple(matches) == ("A", "A")
def test_sanity(): matches = Matches( """A 1 C 4 A 6 7 D""", Context(), Pattern("\d"), ) assert tuple(matches) == ("1", "4", "6", "7")
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")
def test_color(): matches = Matches("ABCDE", Context(), "B.D", color="red") assert tuple(matches) == (color_str("ABCDE", "red"), )
def test_only_matched(): matches = Matches("ABCDE", Context(), "B.D", only_matched=True) assert tuple(matches) == ("BCD", )
def test_zero_based(): matches = Matches("A", Context(), "A", zero_based=True, number_lines=True) assert tuple(matches) == ("0: A", )