Ejemplo n.º 1
0
def test_reg_not_out_of_bounds_at_end():
    # the only way this is triggerable is with an illegal regex, we'd rather
    # produce an error about the regex being wrong than an IndexError
    with pytest.raises(onigurumacffi.OnigError) as excinfo:
        _Reg('\\A\\')
    msg, = excinfo.value.args
    assert msg == 'end pattern at escape'
Ejemplo n.º 2
0
def test_reg_first_line():
    reg = _Reg(r'\Ahello')
    assert reg.match('hello', 0, first_line=True, boundary=True)
    assert reg.search('hello', 0, first_line=True, boundary=True)
    assert not reg.match('hello', 0, first_line=False, boundary=True)
    assert not reg.search('hello', 0, first_line=False, boundary=True)
Ejemplo n.º 3
0
def test_reg_repr():
    assert repr(_Reg(r'\A123')) == r"_Reg('\\A123')"
Ejemplo n.º 4
0
def test_reg_other_escapes_left_untouched():
    reg = _Reg(r'(^|\A|\G)\w\s\w')
    assert reg.match('a b', 0, first_line=False, boundary=False)
Ejemplo n.º 5
0
def test_reg_neither():
    reg = _Reg(r'(\A|\G)hello')
    assert not reg.search('hello', 0, first_line=False, boundary=False)
    assert not reg.search('ohello', 1, first_line=False, boundary=False)
Ejemplo n.º 6
0
def test_reg_boundary():
    reg = _Reg(r'\Ghello')
    assert reg.search('ohello', 1, first_line=True, boundary=True)
    assert reg.match('ohello', 1, first_line=True, boundary=True)
    assert not reg.search('ohello', 1, first_line=True, boundary=False)
    assert not reg.match('ohello', 1, first_line=True, boundary=False)