Пример #1
0
 def test_star_2(self):
     expr = StateSplit(None, StateMatch())
     expr.out = StateChar('a', expr)
     result = find2(expr, 'aaaaaaaabacbca', 0)
     assert list(result) == [
         (1, 8), (9, 8), (10, 10), (11, 10), (12, 11), (13, 12), (14, 14)
     ]
Пример #2
0
def method_find(args):
    s, expr, start, plain = handle_args(args)
    matches = next(find2(expr, s, start))
    if matches == (-1, -1):
        return [W_Pri(0)]
    else:
        return [W_Num(matches[0]), W_Num(matches[1])]
Пример #3
0
def method_match(args):
    s, expr, start, plain = handle_args(args)
    start_i, stop_i = next(find2(expr, s, start))
    if (start_i, stop_i) == (-1, -1):
        return [W_Pri(0)]
    else:
        return [W_Str(s[start_i-1:stop_i])]
Пример #4
0
 def test_star_1(self):
     expr = StateSplit(None, StateMatch())
     expr.out = StateChar('c', expr)
     result = find2(expr, 'aaaabacccca', 0)
     assert list(result) == [
         (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 10),
         (11, 10)
     ]
Пример #5
0
def method_gsub(args):
    s = args[0].s_val
    pattern = args[1].s_val
    replace = args[2].s_val
    expr = compile_re(pattern, False)
    sublist = []
    last_stop = 0
    for m_start, m_stop in find2(expr, s, 0):
        if (m_start, m_stop) == (-1, -1):
            return [W_Str(s)]
        else:
            sublist.append(s[last_stop:m_start-1])
            sublist.append(replace)
            last_stop = m_stop
    sublist.append(s[last_stop:])
    res = "".join(sublist)
    return [W_Str(res)]
Пример #6
0
 def test_single_char_more_matches(self):
     expr = StateChar('c', StateMatch())
     result = find2(expr, 'xyzaaaccaa', 0)
     assert list(result) == [(7, 7), (8, 8)]
Пример #7
0
 def test_two_chars_no_matches(self):
     expr = StateChar('a', StateChar('b', StateMatch()))
     result = find2(expr, 'acbaaubbbbb', 0)
     assert list(result) == [(-1, -1)]
Пример #8
0
 def test_simple_or(self):
     expr = compile_re('(aa|bb)')
     result = find2(expr, 'xyzabbaab', 0)
     assert list(result) == [(5, 6), (7, 8)]
Пример #9
0
 def test_chained_grouped_or_match(self):
     expr = compile_re('x(aa|bb)(cc|dd)x')
     result = find2(expr, 'axaaddaxbbccxxaacx', 0)
     assert list(result) == [(8, 13)]
Пример #10
0
 def test_three_chars_one_matches_offset(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'abcjjjabc', 4)
     assert list(result) == [(7, 9)]
Пример #11
0
 def test_three_chars_big_negative_offset_match(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'abcjjjabc', -100)
     assert list(result) == [(1, 3), (7, 9)]
Пример #12
0
 def test_grouped_star_and_or_no_match(self):
     expr = compile_re('x((aa)*|(bb)*)x')
     result = find2(expr, 'xaaaaaxbxabxbbbb', 0)
     assert list(result) == [(-1, -1)]
Пример #13
0
 def test_three_chars_one_match(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'ccabababccbababacccbaccabbbc', 0)
     assert list(result) == [(7, 9)]
Пример #14
0
 def test_grouped_star_between_chars_no_match(self):
     expr = compile_re('x(ab)*x')
     result = find2(expr, 'ababxabababab', 0)
     assert list(result) == [(-1, -1)]
Пример #15
0
 def test_grouped_star_and_or_match(self):
     expr = compile_re('x((aa)*|(bb)*)x')
     result = find2(expr, 'xaaaaaaxxx', 0)
     assert list(result) == [(1, 8), (9, 10)]
Пример #16
0
 def test_single_char_one_match(self):
     expr = StateChar('c', StateMatch())
     result = find2(expr, 'asdasdxcz', 0)
     assert list(result) == [(8, 8)]
Пример #17
0
 def test_grouped_star(self):
     expr = compile_re('(ab)*')
     result = find2(expr, 'ababababab', 0)
     assert list(result) == [(1, 10)]
Пример #18
0
 def test_chained_grouped_or_no_match(self):
     expr = compile_re('x(aa|bb)(cc|dd)x')
     result = find2(expr, 'xaaccddxxaaddddxxaacc', 0)
     assert list(result) == [(-1, -1)]
Пример #19
0
 def test_two_chars_one_match(self):
     expr = StateChar('a', StateChar('b', StateMatch()))
     result = find2(expr, 'ccvvvbbajbajbabb', 0)
     assert list(result) == [(14, 15)]
Пример #20
0
 def test_simple_plus(self):
     expr = compile_re('a+')
     result = find2(expr, 'bxaaaabak', 0)
     assert list(result) == [(3, 6), (8, 8)]
Пример #21
0
 def tests_find_two_chars_matches(self):
     expr = StateChar('a', StateChar('b', StateMatch()))
     result = find2(expr, 'baaaabbacaabbcc', 0)
     assert list(result) == [(5, 6), (11, 12)]
Пример #22
0
 def test_grouped_plus(self):
     expr = compile_re('(a|b)+c')
     result = find2(expr, 'xxcaababcvbc', 0)
     assert list(result) == [(4, 9), (11, 12)]
Пример #23
0
 def test_three_chars_two_matches(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'babcccabababccbababacccbaccabbbc', 0)
     assert list(result) == [(2, 4), (11, 13)]
Пример #24
0
 def test_single_char_no_match(self):
     expr = StateChar('c', StateMatch())
     result = find2(expr, 'xyz', 0)
     assert list(result) == [(-1, -1)]
Пример #25
0
 def test_three_chars_negative_offset_no_match(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'abcjjjabc', -2)
     assert list(result) == [(-1, -1)]
Пример #26
0
 def test_star_between_chars_match_star(self):
     star = StateSplit(None, StateChar('c', StateMatch()))
     star.out = StateChar('b', star)
     expr = StateChar('a', star)
     result = find2(expr, 'xaabbbbbcjjjabcxalcac', 0)
     assert list(result) == [(3, 9), (13, 15), (20, 21)]
Пример #27
0
 def test_three_chars_big_offset(self):
     expr = StateChar('a', StateChar('b', StateChar('c', StateMatch())))
     result = find2(expr, 'abcjjjabc', 100)
     assert list(result) == [(-1, -1)]
Пример #28
0
 def test_match_evil_no_match(self):
     expr = compile_re('(a|b)*a(a|b){5}a(a|b)*')
     result = find2(expr, 'aaaaaaxbbbbaaaaabbbbbbb', 0)
     assert list(result) == [(-1, -1)]
Пример #29
0
 def test_or_repetition(self):
     expr = compile_re('(aa|bb){2}')
     result = find2(expr, 'xabbxaaaaxjkbbajbbaal', 0)
     assert list(result) == [(6, 9), (17, 20)]
Пример #30
0
 def test_grouped_or_between_chars(self):
     expr = compile_re('x(aa|bb)x')
     result = find2(expr, 'axaaxaxbxbbxa', 0)
     assert list(result) == [(2, 5), (9, 12)]
Пример #31
0
 def test_star_between_chars_star_match_end(self):
     star = StateSplit(None, StateMatch())
     star.out = StateChar('b', star)
     expr = StateChar('a', star)
     result = find2(expr, 'acjjjabcabbbbb', 0)
     assert list(result) == [(1, 1), (6, 7), (9, 14)]
Пример #32
0
 def test_match_evil(self):
     expr = compile_re('(a|b)*a(a|b){5}a(a|b)*')
     result = find2(expr, 'aaaababababba', 0)
     assert list(result) == [(1, 13)]