Ejemplo n.º 1
0
def test_star_group_trailing():
    _check(
        r'a(bb)*a(c|d|e|fg)hij',
        'aafghij trailing',
        'aafghij',
    )
    _check(
        r'a(bb)*a(c|d|e|fg)hij',
        'abbbbafghij trailing',
        'abbbbafghij',
    )
Ejemplo n.º 2
0
def test_nested_groups():
    match = _check('a((b)(c))', 'abc', 'abc')
    assert match.text == {
        0: 'abc',
        1: 'bc',
        2: 'b',
        3: 'c',
    }
    assert match.extents == {
        0: (0, 3),
        1: (1, 3),
        2: (1, 2),
        3: (2, 3),
    }
    _check('a((b)(c))', 'acb', None)
Ejemplo n.º 3
0
def test_star_simple():
    _check(
        r'ab*a',
        'aba',
        'aba',
    )
    _check(
        r'ab*a',
        'aa',
        'aa',
    )
    _check(
        r'ab*a',
        'abba',
        'abba',
    )
    _check(
        r'ab*a',
        'ada',
        None,
    )
Ejemplo n.º 4
0
def test_plus_group_trailing():
    _check(
        r'a(bb)+a(c|d|e|fg)hij',
        'abbbbafghij trailing',
        'abbbbafghij',
    )
Ejemplo n.º 5
0
def test_only_prefix_matches_with_group():
    _check('a(a|b|c)', 'aab', 'aa')
Ejemplo n.º 6
0
def test_alternative_in_group():
    _check('a(a|b|c)', 'aa', 'aa')
    _check('a(a|b|c)', 'ab', 'ab')
    _check('a(a|b|c)', 'ac', 'ac')
    _check('a(a|b|c)', 'ad', None)
    _check('a(a|b|c)', 'a', None)
Ejemplo n.º 7
0
def test_alternatives():
    _check('a|b|c', 'a', 'a')
    _check('a|b|c', 'b', 'b')
    _check('a|b|c', 'c', 'c')
    _check('a|b|c', 'd', None)
Ejemplo n.º 8
0
def test_simple():
    _check(
        r'aba',
        'aba',
        'aba',
    )
Ejemplo n.º 9
0
def test_plus():
    _check('a+a', 'aaa', 'aaa')
    _check('a+a', 'aaaa', 'aaaa')
    _check('a+a', 'aa', 'aa')
    _check('a+a', 'a', None)
Ejemplo n.º 10
0
def test_trailing():
    _check(
        r'ab',
        'aba',
        'ab',
    )
Ejemplo n.º 11
0
def test_not_first_substring():
    match = _check('a', 'baab', 'a')
    assert match.extents == {
        0: (1, 2),
    }
Ejemplo n.º 12
0
def test_complex_with_trailing():
    _check(
        r'ab?c+.(first(second|third)+)',
        r'abc.firstsecondthird trailing',
        r'abc.firstsecondthird',
    )
Ejemplo n.º 13
0
def test_groups_common_prefix():
    _check('a((bc)|(bd))+', 'abc', 'abc')
    _check('a((bc)|(bd))+', 'abcbd', 'abcbd')
    _check('a((bc)|(bd))+', 'abd', 'abd')
    _check('a((bc)|(bd))+', 'abdbc', 'abdbc')
    _check('a((bc)|(bd))+', 'acd', None)