def test_adjacent_capture_sequences(): grepper = Grepper("the %{0S1} %{1} ran away") match = grepper.match_line("the big brown fox ran away") assert bool(match) assert match.token(0) == "big brown" assert match.token(1) == "fox" assert match.re == re.compile( "^the\\ (?P<token_0>(?:\\S*\\s\\S*){1}\\S*)\\ (?P<token_1>.*?)\\ ran\\ away$" ) assert match.pattern == "the %{0S1} %{1} ran away"
def test_matches_multiple_patterns(line, expected): grepper = Grepper("foo", "baz") assert bool(grepper.match_line(line)) == expected
def test_patterns(pattern, test_string, expected): grepper = Grepper(pattern) assert bool(grepper.match_line(test_string)) == expected