<commit_before>from luna.modules.patterns import build_expr, find, Char, Sequence, Dot, CharRange


class TestPattern(object):
    def test_single_char_no_match(self):
        expr = Char('c')
        result = find(expr, 'xyz', 0)
        assert result == (-1, -1)

    def test_single_char_one_match(self):
        expr = Char('c')
        result = find(expr, 'asdasdxcz', 0)
        assert result == (8, 8)

    def test_single_char_more_matches(self):
        expr = Char('c')
        result = find(expr, 'xyzaaaccaa', 0)
        assert result == (7, 7)

    def test_two_chars_no_matches(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'acbaaubbbbb', 0)
        assert result == (-1, -1)

    def test_two_chars_one_match(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'ccvvvbbajbajbabb', 0)
        assert result == (14, 15)

    def test_two_chars_two_matches(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'baaaabbacaabbcc', 0)
        assert result == (5, 6)

    def test_three_chars_no_matches(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'ccababababababacccbaccabbbc', 0)
        assert result == (-1, -1)

    def test_three_chars_one_matches(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'ccabababccbababacccbaccabbbc', 0)
        assert result == (7, 9)

    def test_three_chars_one_matches_offset(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', 4)
        assert result == (7, 9)

    def test_three_chars_negative_offset_no_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -2)
        assert result == (-1, -1)

    def test_three_chars_negative_offset_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -3)
        assert result == (7, 9)

    def test_three_chars_big_negative_offset_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -100)
        assert result == (1, 3)

    def test_three_chars_big_offset(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', 100)
        assert result == (-1, -1)

    def test_single_char_build_expr(self):
        expr = build_expr('a', False)
        assert isinstance(expr, Char)
        assert expr.start == ord('a')

    def test_two_chars_build_expr(self):
        expr = build_expr('ab', False)<commit_msg>Add simple tests for Kleene star<commit_after>from luna.modules.patterns import build_expr, find, Char, Sequence, Dot, CharRange, Star


class TestPattern(object):
    def test_single_char_no_match(self):
        expr = Char('c')
        result = find(expr, 'xyz', 0)
        assert result == (-1, -1)

    def test_single_char_one_match(self):
        expr = Char('c')
        result = find(expr, 'asdasdxcz', 0)
        assert result == (8, 8)

    def test_single_char_more_matches(self):
        expr = Char('c')
        result = find(expr, 'xyzaaaccaa', 0)
        assert result == (7, 7)

    def test_two_chars_no_matches(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'acbaaubbbbb', 0)
        assert result == (-1, -1)

    def test_two_chars_one_match(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'ccvvvbbajbajbabb', 0)
        assert result == (14, 15)

    def test_two_chars_two_matches(self):
        expr = Sequence(Char('a'), Char('b'))
        result = find(expr, 'baaaabbacaabbcc', 0)
        assert result == (5, 6)

    def test_three_chars_no_matches(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'ccababababababacccbaccabbbc', 0)
        assert result == (-1, -1)

    def test_three_chars_one_matches(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'ccabababccbababacccbaccabbbc', 0)
        assert result == (7, 9)

    def test_three_chars_one_matches_offset(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', 4)
        assert result == (7, 9)

    def test_three_chars_negative_offset_no_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -2)
        assert result == (-1, -1)

    def test_three_chars_negative_offset_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -3)
        assert result == (7, 9)

    def test_three_chars_big_negative_offset_match(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', -100)
        assert result == (1, 3)

    def test_three_chars_big_offset(self):
        expr = Sequence(Sequence(Char('a'), Char('b')), Char('c'))
        result = find(expr, 'abcjjjabc', 100)
        assert result == (-1, -1)

    def test_star_1(self):
        expr = Star(Char('c'))
        result = find(expr, 'aaaaaaaabacccca', 0)
        assert result == (1, 0)

    def test_star_2(self):
        expr = Star(Char('a'))
        result = find(expr, 'aaaaaaaabacccca', 0)
        assert result == (1, 8)

    def test_star_between_chart_star_between_charss(self):
        expr = Sequence(Char('a'), Star(Char('b')))
        result = find(expr, 'acjjjabc', 0)
        assert result == (1, 1)


    def test_single_char_build_expr(self):
        expr = build_expr('a', False)
        assert isinstance(expr, Char)
        assert expr.start == ord('a')

    def test_two_chars_build_expr(self):
        expr = build_expr('ab', False)
{'fraction_non_alphanumeric': 0.15806288885152178, 'fraction_numerical': 0.016983352951067766, 'mean_word_length': 2.9785953177257527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6940595', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1980, 'n_words': 442}