Example #1
0
def xx(pattern, target, s_from, s_to, mem, not_match):
    global nerror
    global nsucc
    global nfail
    global region

    reg = onig.OnigRegex()
    einfo = onig.OnigErrorInfo()
    syn = onig.OnigSyntaxType()
    msg = create_string_buffer(onig.ONIG_MAX_ERROR_MESSAGE_LEN)

    pattern2 = pattern
    if not isinstance(pattern, bytes):
        pattern2 = pattern.encode(encoding)
    patternp = strptr(pattern2)

    target2 = target
    if not isinstance(target, bytes):
        s_from = cc_to_cb(target, encoding, s_from)
        s_to = cc_to_cb(target, encoding, s_to)
        target2 = target.encode(encoding)
    targetp = strptr(target2)

    # special syntactic settings
    onig.onig_copy_syntax(byref(syn), onig.ONIG_SYNTAX_DEFAULT)
    syn.options &= ~onig.ONIG_OPTION_ASCII_RANGE
    syn.behavior &= ~onig.ONIG_SYN_POSIX_BRACKET_ALWAYS_ALL_RANGE

    r = onig.onig_new(byref(reg), patternp.getptr(), patternp.getptr(-1),
            onig.ONIG_OPTION_DEFAULT, onig_encoding, byref(syn), byref(einfo));
    if r != 0:
        onig.onig_error_code_to_str(msg, r, byref(einfo))
        nerror += 1
        print_result("ERROR", "%s (/%s/ '%s')" % (msg.value, pattern, target),
                file=sys.stderr)
        return

    r = onig.onig_search(reg, targetp.getptr(), targetp.getptr(-1),
                    targetp.getptr(), targetp.getptr(-1),
                    region, onig.ONIG_OPTION_NONE);
    if r < onig.ONIG_MISMATCH:
        onig.onig_error_code_to_str(msg, r)
        nerror += 1
        print_result("ERROR", "%s (/%s/ '%s')" % (msg.value, pattern, target),
                file=sys.stderr)
        return

    if r == onig.ONIG_MISMATCH:
        if not_match:
            nsucc += 1
            print_result("OK(N)", "/%s/ '%s'" % (pattern, target))
        else:
            nfail += 1
            print_result("FAIL", "/%s/ '%s'" % (pattern, target))
    else:
        if not_match:
            nfail += 1
            print_result("FAIL(N)", "/%s/ '%s'" % (pattern, target))
        else:
            start = region[0].beg[mem]
            end = region[0].end[mem]
            if (start == s_from) and (end == s_to):
                nsucc += 1
                print_result("OK", "/%s/ '%s'" % (pattern, target))
            else:
                nfail += 1
                print_result("FAIL", "/%s/ '%s' %d-%d : %d-%d" % (pattern, target,
                        s_from, s_to, start, end))
    onig.onig_free(reg)
Example #2
0
def xx(
    pattern,
    target,
    s_from,
    s_to,
    mem,
    not_match,
    syn=syntax_default,
    opt=onig.ONIG_OPTION_DEFAULT,
    err=onig.ONIG_NORMAL,
):
    global nerror
    global nsucc
    global nfail

    reg = onig.OnigRegex()
    einfo = onig.OnigErrorInfo()
    msg = create_string_buffer(onig.ONIG_MAX_ERROR_MESSAGE_LEN)

    pattern2 = pattern
    if not isinstance(pattern, bytes):
        pattern2 = pattern.encode(encoding)
    patternp = strptr(pattern2)

    target2 = target
    if not isinstance(target, bytes):
        s_from = cc_to_cb(target, encoding, s_from)
        s_to = cc_to_cb(target, encoding, s_to)
        target2 = target.encode(encoding)
    targetp = strptr(target2)

    # cut very long outputs
    limit = 100
    if len(target) > limit:
        target = target[:limit] + "..."
    if len(pattern) > limit:
        pattern = pattern[:limit] + "..."

    r = onig.onig_new(byref(reg), patternp.getptr(), patternp.getptr(-1), opt, onig_encoding, syn, byref(einfo))
    if r != 0:
        onig.onig_error_code_to_str(msg, r, byref(einfo))
        if r == err:
            nsucc += 1
            print_result("OK(E)", "%s (/%s/ '%s')" % (msg.value.decode(), pattern, target))
        else:
            nerror += 1
            print_result("ERROR", "%s (/%s/ '%s')" % (msg.value.decode(), pattern, target), file=sys.stderr)
        return

    if err != onig.ONIG_NORMAL:
        nfail += 1
        print_result("FAIL(E)", "/%s/ '%s'" % (pattern, target))
        onig.onig_free(reg)
        return

    region = onig.onig_region_new()
    r = onig.onig_search(
        reg, targetp.getptr(), targetp.getptr(-1), targetp.getptr(), targetp.getptr(-1), region, onig.ONIG_OPTION_NONE
    )
    if r < onig.ONIG_MISMATCH:
        onig.onig_error_code_to_str(msg, r)
        if r == err:
            nsucc += 1
            print_result("OK(E)", "%s (/%s/ '%s')" % (msg.value.decode(), pattern, target))
        else:
            nerror += 1
            print_result("ERROR", "%s (/%s/ '%s')" % (msg.value.decode(), pattern, target), file=sys.stderr)
        onig.onig_region_free(region, 1)
        return

    if r == onig.ONIG_MISMATCH:
        if not_match:
            nsucc += 1
            print_result("OK(N)", "/%s/ '%s'" % (pattern, target))
        else:
            nfail += 1
            print_result("FAIL", "/%s/ '%s'" % (pattern, target))
    else:
        if not_match:
            nfail += 1
            print_result("FAIL(N)", "/%s/ '%s'" % (pattern, target))
        else:
            start = region[0].beg[mem]
            end = region[0].end[mem]
            if (start == s_from) and (end == s_to):
                nsucc += 1
                print_result("OK", "/%s/ '%s'" % (pattern, target))
            else:
                nfail += 1
                print_result("FAIL", "/%s/ '%s' %d-%d : %d-%d" % (pattern, target, s_from, s_to, start, end))
    onig.onig_free(reg)
    onig.onig_region_free(region, 1)
Example #3
0
def xx(pattern, target, s_from, s_to, mem, not_match):
    global nerror
    global nsucc
    global nfail
    global region
    
    reg = onig.OnigRegex()
    einfo = onig.OnigErrorInfo()
    syn = onig.OnigSyntaxType()
    msg = create_string_buffer(onig.ONIG_MAX_ERROR_MESSAGE_LEN)
    
    pattern2 = pattern
    if not isinstance(pattern, bytes):
        pattern2 = pattern.encode(encoding)
    patternp = strptr(pattern2)
    
    target2 = target
    if not isinstance(target, bytes):
        s_from = cc_to_cb(target, encoding, s_from)
        s_to = cc_to_cb(target, encoding, s_to)
        target2 = target.encode(encoding)
    targetp = strptr(target2)
    
    onig.onig_copy_syntax(byref(syn), onig.ONIG_SYNTAX_DEFAULT)
    syn.options = syn.options & ~onig.ONIG_OPTION_ASCII_RANGE
    
    r = onig.onig_new(byref(reg), patternp.getptr(), patternp.getptr(-1),
            onig.ONIG_OPTION_DEFAULT, onig_encoding, byref(syn), byref(einfo));
    if r != 0:
        onig.onig_error_code_to_str(msg, r, byref(einfo))
        nerror += 1
        print_result("ERROR", "%s (/%s/ '%s')" % (msg.value, pattern, target),
                file=sys.stderr)
        return
    
    r = onig.onig_search(reg, targetp.getptr(), targetp.getptr(-1),
                    targetp.getptr(), targetp.getptr(-1),
                    region, onig.ONIG_OPTION_NONE);
    if r < onig.ONIG_MISMATCH:
        onig.onig_error_code_to_str(msg, r)
        nerror += 1
        print_result("ERROR", "%s (/%s/ '%s')" % (msg.value, pattern, target),
                file=sys.stderr)
        return
    
    if r == onig.ONIG_MISMATCH:
        if not_match:
            nsucc += 1
            print_result("OK(N)", "/%s/ '%s'" % (pattern, target))
        else:
            nfail += 1
            print_result("FAIL", "/%s/ '%s'" % (pattern, target))
    else:
        if not_match:
            nfail += 1
            print_result("FAIL(N)", "/%s/ '%s'" % (pattern, target))
        else:
            start = region[0].beg[mem]
            end = region[0].end[mem]
            if (start == s_from) and (end == s_to):
                nsucc += 1
                print_result("OK", "/%s/ '%s'" % (pattern, target))
            else:
                nfail += 1
                print_result("FAIL", "/%s/ '%s' %d-%d : %d-%d" % (pattern, target,
                        s_from, s_to, start, end))
    onig.onig_free(reg)
Example #4
0
def xx(pattern,
       target,
       s_from,
       s_to,
       mem,
       not_match,
       syn=syntax_default,
       opt=onig.ONIG_OPTION_DEFAULT,
       err=onig.ONIG_NORMAL):
    global nerror
    global nsucc
    global nfail

    reg = onig.OnigRegex()
    einfo = onig.OnigErrorInfo()
    msg = create_string_buffer(onig.ONIG_MAX_ERROR_MESSAGE_LEN)

    pattern2 = pattern
    if not isinstance(pattern, bytes):
        pattern2 = pattern.encode(encoding)
    patternp = strptr(pattern2)

    target2 = target
    if not isinstance(target, bytes):
        s_from = cc_to_cb(target, encoding, s_from)
        s_to = cc_to_cb(target, encoding, s_to)
        target2 = target.encode(encoding)
    targetp = strptr(target2)

    # cut very long outputs
    limit = 100
    if len(target) > limit:
        target = target[:limit] + "..."
    if len(pattern) > limit:
        pattern = pattern[:limit] + "..."

    r = onig.onig_new(byref(reg), patternp.getptr(), patternp.getptr(-1), opt,
                      onig_encoding, syn, byref(einfo))
    if r != 0:
        onig.onig_error_code_to_str(msg, r, byref(einfo))
        if r == err:
            nsucc += 1
            print_result("OK(E)", "%s (/%s/ '%s')" % \
                    (msg.value.decode(), pattern, target))
        else:
            nerror += 1
            print_result("ERROR", "%s (/%s/ '%s')" % \
                    (msg.value.decode(), pattern, target), file=sys.stderr)
        return

    if err != onig.ONIG_NORMAL:
        nfail += 1
        print_result("FAIL(E)", "/%s/ '%s'" % (pattern, target))
        onig.onig_free(reg)
        return

    region = onig.onig_region_new()
    r = onig.onig_search(reg, targetp.getptr(), targetp.getptr(-1),
                         targetp.getptr(), targetp.getptr(-1), region,
                         onig.ONIG_OPTION_NONE)
    if r < onig.ONIG_MISMATCH:
        onig.onig_error_code_to_str(msg, r)
        if r == err:
            nsucc += 1
            print_result("OK(E)", "%s (/%s/ '%s')" % \
                    (msg.value.decode(), pattern, target))
        else:
            nerror += 1
            print_result("ERROR", "%s (/%s/ '%s')" % \
                    (msg.value.decode(), pattern, target), file=sys.stderr)
        onig.onig_region_free(region, 1)
        return

    if r == onig.ONIG_MISMATCH:
        if not_match:
            nsucc += 1
            print_result("OK(N)", "/%s/ '%s'" % (pattern, target))
        else:
            nfail += 1
            print_result("FAIL", "/%s/ '%s'" % (pattern, target))
    else:
        if not_match:
            nfail += 1
            print_result("FAIL(N)", "/%s/ '%s'" % (pattern, target))
        else:
            start = region[0].beg[mem]
            end = region[0].end[mem]
            if (start == s_from) and (end == s_to):
                nsucc += 1
                print_result("OK", "/%s/ '%s'" % (pattern, target))
            else:
                nfail += 1
                print_result(
                    "FAIL", "/%s/ '%s' %d-%d : %d-%d" %
                    (pattern, target, s_from, s_to, start, end))
    onig.onig_free(reg)
    onig.onig_region_free(region, 1)