コード例 #1
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_with_value(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile(r'(.*)%s' % outgroup)
    reversed_re = unmatcher.reverse(the_re, ingroup)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() == (ingroup,)
コード例 #2
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_condition_with_value(condgroup, yesgroup):
    if not condgroup:
        return
    the_re = re.compile('(%s)?((?(1)%s))' % (condgroup, yesgroup))
    reversed_re = unmatcher.reverse(the_re, condgroup)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() in [(condgroup, yesgroup), (None, "")]
コード例 #3
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_with_value(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile(r'(.*)%s' % outgroup)
    reversed_re = unmatcher.reverse(the_re, ingroup)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() == (ingroup, )
コード例 #4
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_condition_with_value(condgroup, yesgroup):
    if not condgroup:
        return
    the_re = re.compile('(%s)?((?(1)%s))' % (condgroup, yesgroup))
    reversed_re = unmatcher.reverse(the_re, condgroup)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() in [(condgroup, yesgroup), (None, "")]
コード例 #5
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_with_backrefs(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile(r'(%s)%s\1' % (ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() == (ingroup, )
コード例 #6
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_noncapture_group(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile('(?:%s)%s' % (ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert len(match.groups()) == 0
コード例 #7
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_noncapture_group(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile('(?:%s)%s' % (ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert len(match.groups()) == 0
コード例 #8
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_group_with_backrefs(ingroup, outgroup):
    if not ingroup:
        return
    the_re = re.compile(r'(%s)%s\1' % (ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groups() == (ingroup,)
コード例 #9
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_sans_backrefs(groupname, ingroup, outgroup):
    if not (groupname and ingroup):
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile('(?P<%s>%s)%s' % (groupname, ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groupdict() == {groupname: ingroup}
コード例 #10
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_with_value(groupname, ingroup, outgroup):
    if not (groupname and ingroup):
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile(r'(?P<%s>.*)%s' % (groupname, outgroup))
    reversed_re = unmatcher.reverse(the_re, **{groupname: ingroup})
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groupdict() == {groupname: ingroup}
コード例 #11
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_with_value(groupname, ingroup, outgroup):
    if not (groupname and ingroup):
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile(r'(?P<%s>.*)%s' % (groupname, outgroup))
    reversed_re = unmatcher.reverse(the_re, **{groupname: ingroup})
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groupdict() == {groupname: ingroup}
コード例 #12
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_sans_backrefs(groupname, ingroup, outgroup):
    if not (groupname and ingroup):
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile('(?P<%s>%s)%s' % (groupname, ingroup, outgroup))
    reversed_re = unmatcher.reverse(the_re)
    match = the_re.match(reversed_re)
    assert bool(match)
    assert match.groupdict() == {groupname: ingroup}
コード例 #13
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_repeat_symbols(symbol, char):
    repeat_re = re.compile('%s%s' % (re.escape(char), symbol))
    reversed_repeat = unmatcher.reverse(repeat_re)
    assert bool(repeat_re.match(reversed_repeat))
    if len(reversed_repeat) == 0:
        assert symbol == '*', "empty string for repeater other than `*'"
    else:
        for chunk in chunks(reversed_repeat, len(char)):
            assert char == chunk
コード例 #14
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_repeat_symbols(symbol, char):
    repeat_re = re.compile('%s%s' % (re.escape(char), symbol))
    reversed_repeat = unmatcher.reverse(repeat_re)
    assert bool(repeat_re.match(reversed_repeat))
    if len(reversed_repeat) == 0:
        assert symbol == '*', "empty string for repeater other than `*'"
    else:
        for chunk in chunks(reversed_repeat, len(char)):
            assert char == chunk
コード例 #15
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_condition_with_value(groupname, condgroup, yesgroup):
    if not condgroup:
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile(
        '(?P<{groupname}>{condgroup})?((?({groupname}){yesgroup}))'.format(
            **locals()))
    reversed_re = unmatcher.reverse(the_re, **{groupname: condgroup})
    match = the_re.match(reversed_re)
    assert bool(match)
    assert (match.group(groupname), match.group(2)) in [(condgroup, yesgroup),
                                                        (None, "")]
コード例 #16
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_named_group_condition_with_value(groupname, condgroup, yesgroup):
    if not condgroup:
        return
    groupname = 'a' + groupname  # cannot start with digit
    the_re = re.compile(
        '(?P<{groupname}>{condgroup})?((?({groupname}){yesgroup}))'
        .format(**locals()))
    reversed_re = unmatcher.reverse(the_re, **{groupname: condgroup})
    match = the_re.match(reversed_re)
    assert bool(match)
    assert (match.group(groupname), match.group(2)) in [(condgroup, yesgroup),
                                                        (None, "")]
コード例 #17
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_repeat_range(lower_bound, upper_bound, char):
    if lower_bound == upper_bound:
        # test exact "range": foo{3}
        repeat_re = re.compile('%s{%d}' % (re.escape(char), lower_bound))
    elif lower_bound < upper_bound:
        # test closed range: foo{2,4}
        repeat_re = re.compile('%s{%d,%d}' %
                               (re.escape(char), lower_bound, upper_bound))
    elif lower_bound > upper_bound:
        # test "infinite" range: foo{4,}
        lower_bound = min((lower_bound, upper_bound))
        repeat_re = re.compile('%s{%d,}' % (re.escape(char), lower_bound))
    else:
        pytest.fail()  # FSM help you if that actually happens

    reversed_repeat = unmatcher.reverse(repeat_re)
    assert bool(repeat_re.match(reversed_repeat))
    for chunk in chunks(reversed_repeat, len(char)):
        assert char == chunk
コード例 #18
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_repeat_range(lower_bound, upper_bound, char):
    if lower_bound == upper_bound:
        # test exact "range": foo{3}
        repeat_re = re.compile('%s{%d}' % (re.escape(char), lower_bound))
    elif lower_bound < upper_bound:
        # test closed range: foo{2,4}
        repeat_re = re.compile('%s{%d,%d}' % (re.escape(char),
                                              lower_bound, upper_bound))
    elif lower_bound > upper_bound:
        # test "infinite" range: foo{4,}
        lower_bound = min((lower_bound, upper_bound))
        repeat_re = re.compile('%s{%d,}' % (re.escape(char), lower_bound))
    else:
        pytest.fail()  # FSM help you if that actually happens

    reversed_repeat = unmatcher.reverse(repeat_re)
    assert bool(repeat_re.match(reversed_repeat))
    for chunk in chunks(reversed_repeat, len(char)):
        assert char == chunk
コード例 #19
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_not_literal(char):
    assert char != unmatcher.reverse('[^%s]' % re.escape(char))
コード例 #20
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_negate_class(class_):
    charset_re = re.compile(r'\%s' % class_.upper())
    reversed_charset = unmatcher.reverse(charset_re)
    assert bool(charset_re.match(reversed_charset))
コード例 #21
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_explicitly_unsupported_cases(case):
    """Explicitly unsupported cases should not fail with just generic error."""
    node_type, regex = case
    with pytest.raises(NotImplementedError) as e:
        unmatcher.reverse(regex)
    assert (": " + node_type) not in str(e)
コード例 #22
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_negate_range(minchar, maxchar):
    minchar, maxchar = min(minchar, maxchar), max(minchar, maxchar)
    charset_re = re.compile('[^%s-%s]' % (minchar, maxchar))
    reversed_charset = unmatcher.reverse(charset_re)
    assert reversed_charset < minchar or maxchar < reversed_charset
コード例 #23
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_negate_range(minchar, maxchar):
    minchar, maxchar = min(minchar, maxchar), max(minchar, maxchar)
    charset_re = re.compile('[^%s-%s]' % (minchar, maxchar))
    reversed_charset = unmatcher.reverse(charset_re)
    assert reversed_charset < minchar or maxchar < reversed_charset
コード例 #24
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_branch(left, right):
    branch_re = re.compile('|'.join(map(re.escape, (left, right))))
    reversed_branch = unmatcher.reverse(branch_re)
    assert reversed_branch in (left, right)
コード例 #25
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_unicode_literal(phrase):
    assert phrase == unmatcher.reverse(re.escape(phrase))
コード例 #26
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_literal__ignorecase(expr):
    literal_re = re.compile(expr, re.IGNORECASE)
    reversed_re = unmatcher.reverse(literal_re)
    assert expr.lower() == reversed_re.lower()
コード例 #27
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_unicode_literal(phrase):
    assert phrase == unmatcher.reverse(re.escape(phrase))
コード例 #28
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_literal(expr):
    assert expr == unmatcher.reverse(re.escape(expr))
コード例 #29
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_any(_):
    dot_re = re.compile('.')
    reversed_dot = unmatcher.reverse(dot_re)
    assert bool(dot_re.match(reversed_dot))
    assert reversed_dot != "\n"
コード例 #30
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_literal(expr):
    assert expr == unmatcher.reverse(re.escape(expr))
コード例 #31
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_not_literal(char):
    assert char != unmatcher.reverse('[^%s]' % re.escape(char))
コード例 #32
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_negate_class(class_):
    charset_re = re.compile(r'\%s' % class_.upper())
    reversed_charset = unmatcher.reverse(charset_re)
    assert bool(charset_re.match(reversed_charset))
コード例 #33
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_not_literal__ignore_case(char):
    literal_re = re.compile('[^%s]' % re.escape(char), re.IGNORECASE)
    reversed_re = unmatcher.reverse(literal_re)
    assert reversed_re not in (char.lower(), char.upper())
コード例 #34
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_any(_):
    dot_re = re.compile('.')
    reversed_dot = unmatcher.reverse(dot_re)
    assert bool(dot_re.match(reversed_dot))
    assert reversed_dot != "\n"
コード例 #35
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_explicitly_unsupported_cases(case):
    """Explicitly unsupported cases should not fail with just generic error."""
    node_type, regex = case
    with pytest.raises(NotImplementedError) as e:
        unmatcher.reverse(regex)
    assert (": " + node_type) not in str(e)
コード例 #36
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_any__dotall(_):
    dot_re = re.compile('.', re.DOTALL)
    reversed_dot = unmatcher.reverse(dot_re)
    assert bool(dot_re.match(reversed_dot))
コード例 #37
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_literal__ignorecase(expr):
    literal_re = re.compile(expr, re.IGNORECASE)
    reversed_re = unmatcher.reverse(literal_re)
    assert expr.lower() == reversed_re.lower()
コード例 #38
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_branch(left, right):
    branch_re = re.compile('|'.join(map(re.escape, (left, right))))
    reversed_branch = unmatcher.reverse(branch_re)
    assert reversed_branch in (left, right)
コード例 #39
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_not_literal__ignore_case(char):
    literal_re = re.compile('[^%s]' % re.escape(char), re.IGNORECASE)
    reversed_re = unmatcher.reverse(literal_re)
    assert reversed_re not in (char.lower(), char.upper())
コード例 #40
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_literal(chars):
    if not chars:
        return
    charset_re = re.compile('[%s]' % chars)
    reversed_charset = unmatcher.reverse(charset_re)
    assert reversed_charset in chars
コード例 #41
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_any__dotall(_):
    dot_re = re.compile('.', re.DOTALL)
    reversed_dot = unmatcher.reverse(dot_re)
    assert bool(dot_re.match(reversed_dot))
コード例 #42
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_range(minchar, maxchar):
    minchar, maxchar = min(minchar, maxchar), max(minchar, maxchar)
    charset_re = re.compile('[%s-%s]' % (minchar, maxchar))
    reversed_charset = unmatcher.reverse(charset_re)
    assert minchar <= reversed_charset <= maxchar
コード例 #43
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_literal(chars):
    if not chars:
        return
    charset_re = re.compile('[%s]' % chars)
    reversed_charset = unmatcher.reverse(charset_re)
    assert reversed_charset in chars
コード例 #44
0
ファイル: test_unmatcher.py プロジェクト: Xion/unmatcher
def test_charset_range(minchar, maxchar):
    minchar, maxchar = min(minchar, maxchar), max(minchar, maxchar)
    charset_re = re.compile('[%s-%s]' % (minchar, maxchar))
    reversed_charset = unmatcher.reverse(charset_re)
    assert minchar <= reversed_charset <= maxchar