示例#1
0
def test_match_with_flags():
    reg_A = onigurumacffi.compile(r'\Afoo')
    assert reg_A.match('foo')
    assert not reg_A.match(
        'foo',
        flags=onigurumacffi.OnigSearchOption.NOT_BEGIN_STRING,
    )

    reg_G = onigurumacffi.compile(r'\Gfoo')
    assert reg_G.match('foo')
    assert not reg_G.match(
        'foo',
        flags=onigurumacffi.OnigSearchOption.NOT_BEGIN_POSITION,
    )

    reg_not_G = onigurumacffi.compile(r'(?!\G)')
    assert not reg_not_G.match('foo')
    assert reg_not_G.match(
        'foo',
        flags=onigurumacffi.OnigSearchOption.NOT_BEGIN_POSITION,
    )
示例#2
0
def test_search_with_flags():
    reg_A = onigurumacffi.compile(r'\Afoo')
    assert reg_A.search('foo')
    assert not reg_A.search(
        'foo',
        flags=onigurumacffi.OnigSearchOption.NOT_BEGIN_STRING,
    )

    reg_G = onigurumacffi.compile(r'\Gfoo')
    assert reg_G.search('afoo', start=1)
    assert not reg_G.search(
        'afoo',
        start=1,
        flags=onigurumacffi.OnigSearchOption.NOT_BEGIN_POSITION,
    )

    reg_z = onigurumacffi.compile(r'foo\z')
    assert reg_z.search('hello foo')
    assert not reg_z.search(
        'hello foo',
        flags=onigurumacffi.OnigSearchOption.NOT_END_STRING,
    )
示例#3
0
def test_re_compile_unicode_escape():
    pattern = onigurumacffi.compile(r'"\u2603++"')
    assert pattern.match('"☃☃☃☃"')
示例#4
0
def test_regex_compile_failure():
    with pytest.raises(onigurumacffi.OnigError):
        onigurumacffi.compile('(')
示例#5
0
import pytest

import onigurumacffi

FOO_RE = onigurumacffi.compile('^foo')
ABC_RE = onigurumacffi.compile('(a+)B+(c+)')
UNICODE_RE = onigurumacffi.compile('.*?(🙃+)')
REGSET = onigurumacffi.compile_regset('a+', 'b+', 'c+')


def test_regex_compiles():
    assert FOO_RE is not None


def test_regex_repr():
    assert repr(FOO_RE) == "onigurumacffi.compile('^foo')"


def test_regex_compile_failure():
    with pytest.raises(onigurumacffi.OnigError):
        onigurumacffi.compile('(')


def test_regex_number_of_captures():
    assert FOO_RE.number_of_captures() == 0
    assert ABC_RE.number_of_captures() == 2
    assert UNICODE_RE.number_of_captures() == 1


def test_match_failure():
    assert FOO_RE.match('bar') is None
 def _reg_no_A_no_G(self) -> onigurumacffi._Pattern:
     return onigurumacffi.compile(_replace_esc(self._pattern, 'AG'))
 def _reg(self) -> onigurumacffi._Pattern:
     return onigurumacffi.compile(self._pattern)
示例#8
0
 def __init__(self, s: str) -> None:
     self._pattern = s
     self._reg = onigurumacffi.compile(self._pattern)