Exemplo n.º 1
0
def test_should_match_phone_numbers_without_9_prefix():
    """
    +55 (16) 1122-1213
    ...
    """
    content = read_file()
    match_count = matcher(r'\+\d{2}\s\(\d{2}\)\s\d{4}[-.]\d{4}', content)
    assert match_count == 50
Exemplo n.º 2
0
def test_should_match_all_words_ends_with_at_except_bat():
    content = '''
    cat
    mat
    pat
    bat
    '''
    match_count = matcher(r'[^b]at', content)
    assert match_count == 3
Exemplo n.º 3
0
def test_should_match_phone_numbers():
    """
    +55 (16) 1122-1213
    +55 (16) 91122-1213
    ...
    """
    content = read_file()
    match_count = matcher(r'\+\d{2}\s\(\d{2}\)\s\d{4,5}[-.]\d{4}', content)
    assert match_count == 100
Exemplo n.º 4
0
def test_should_match_phone_numbers_ends_with_1():
    """
    +55 (16) 1122-1211
    +55 (16) 91122-1211
    ...
    """
    content = read_file()
    match_count = matcher(r'\+\d{2}\s\(\d{2}\)\s\d{4,5}[-.]\d{3}[0]', content)
    assert match_count == 10
Exemplo n.º 5
0
def test_should_match_all_prefix_with_regex_groups_more_readble():
    content = '''
    Mr. Schafer
    Mr Smith
    Ms Davis
    Mrs. Robinson
    Mr. T
    '''
    match_count = matcher(r'(Mr|Ms|Mrs)\.?\s[A-Z]\w*', content)
    assert match_count == 5
Exemplo n.º 6
0
def test_should_match_prefix_Mrdot_Mr_and_complete_first_name():
    content = '''
    Mr. Schafer
    Mr Smith
    Ms Davis
    Mrs. Robinson
    Mr. T
    '''
    match_count = matcher(r'Mr\.?\s[A-Z]\w+', content)
    assert match_count == 2
Exemplo n.º 7
0
def test_should_match_prefix_Mrdot_mr():
    content = '''
    Mr. Schafer
    Mr Smith
    Ms Davis
    Mrs. Robinson
    Mr. T
    '''
    match_count = matcher(r'Mr\.?\s[A-Z]\w*', content)
    assert match_count == 3
Exemplo n.º 8
0
def _picktool(repo, ui, path, binary, symlink):
    def check(tool, pat, symlink, binary):
        tmsg = tool
        if pat:
            tmsg += " specified for " + pat
        if not _findtool(ui, tool):
            if pat: # explicitly requested tool deserves a warning
                ui.warn(_("couldn't find merge tool %s\n") % tmsg)
            else: # configured but non-existing tools are more silent
                ui.note(_("couldn't find merge tool %s\n") % tmsg)
        elif symlink and not _toolbool(ui, tool, "symlink"):
            ui.warn(_("tool %s can't handle symlinks\n") % tmsg)
        elif binary and not _toolbool(ui, tool, "binary"):
            ui.warn(_("tool %s can't handle binary\n") % tmsg)
        elif not util.gui() and _toolbool(ui, tool, "gui"):
            ui.warn(_("tool %s requires a GUI\n") % tmsg)
        else:
            return True
        return False

    # HGMERGE takes precedence
    hgmerge = os.environ.get("HGMERGE")
    if hgmerge:
        return (hgmerge, hgmerge)

    # then patterns
    for pat, tool in ui.configitems("merge-patterns"):
        mf = util.matcher(repo.root, "", [pat], [], [])[1]
        if mf(path) and check(tool, pat, symlink, False):
                toolpath = _findtool(ui, tool)
                return (tool, '"' + toolpath + '"')

    # then merge tools
    tools = {}
    for k,v in ui.configitems("merge-tools"):
        t = k.split('.')[0]
        if t not in tools:
            tools[t] = int(_toolstr(ui, t, "priority", "0"))
    names = tools.keys()
    tools = util.sort([(-p,t) for t,p in tools.items()])
    uimerge = ui.config("ui", "merge")
    if uimerge:
        if uimerge not in names:
            return (uimerge, uimerge)
        tools.insert(0, (None, uimerge)) # highest priority
    tools.append((None, "hgmerge")) # the old default, if found
    for p,t in tools:
        if check(t, None, symlink, binary):
            toolpath = _findtool(ui, t)
            return (t, '"' + toolpath + '"')
    # internal merge as last resort
    return (not (symlink or binary) and "internal:merge" or None, None)
Exemplo n.º 9
0
def test_should_match_all_valid_emails():
    content = '''
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    invalid-email1.com
    invalid-email2@
    invalid-email3@com
    invalid-email4@gmail_2.com
    '''
    match_count = matcher(r'[a-zA-Z0-9-_+.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+',
                          content)
    assert match_count == 4
Exemplo n.º 10
0
def _picktool(repo, ui, path, binary, symlink):
    def check(tool, pat, symlink, binary):
        tmsg = tool
        if pat:
            tmsg += " specified for " + pat
        if pat and not _findtool(ui, tool): # skip search if not matching
            ui.warn(_("couldn't find merge tool %s\n") % tmsg)
        elif symlink and not _toolbool(ui, tool, "symlink"):
            ui.warn(_("tool %s can't handle symlinks\n") % tmsg)
        elif binary and not _toolbool(ui, tool, "binary"):
            ui.warn(_("tool %s can't handle binary\n") % tmsg)
        elif not util.gui() and _toolbool(ui, tool, "gui"):
            ui.warn(_("tool %s requires a GUI\n") % tmsg)
        else:
            return True
        return False

    # HGMERGE takes precedence
    hgmerge = os.environ.get("HGMERGE")
    if hgmerge:
        return (hgmerge, hgmerge)

    # then patterns
    for pat, tool in ui.configitems("merge-patterns"):
        mf = util.matcher(repo.root, "", [pat], [], [])[1]
        if mf(path) and check(tool, pat, symlink, False):
                toolpath = _findtool(ui, tool)
                return (tool, '"' + toolpath + '"')

    # then merge tools
    tools = {}
    for k,v in ui.configitems("merge-tools"):
        t = k.split('.')[0]
        if t not in tools:
            tools[t] = int(_toolstr(ui, t, "priority", "0"))
    names = tools.keys()
    tools = [(-p,t) for t,p in tools.items()]
    tools.sort()
    uimerge = ui.config("ui", "merge")
    if uimerge:
        if uimerge not in names:
            return (uimerge, uimerge)
        tools.insert(0, (None, uimerge)) # highest priority
    tools.append((None, "hgmerge")) # the old default, if found
    for p,t in tools:
        toolpath = _findtool(ui, t)
        if toolpath and check(t, None, symlink, binary):
            return (t, '"' + toolpath + '"')
    # internal merge as last resort
    return (not (symlink or binary) and "internal:merge" or None, None)
Exemplo n.º 11
0
def test_should_match_any_spaces_tabs_and_new_lines_characters():
    matches_count = matcher(r'\s', text_to_search)
    assert matches_count == 35
Exemplo n.º 12
0
def test_should_match_any_digit_any_lower_any_upper_and_underscore_letters():
    matches_count = matcher(r'\w', text_to_search)
    assert matches_count == 158
Exemplo n.º 13
0
def test_should_match_any_special_characters_and_spaces():
    matches_count = matcher(r'\W', text_to_search)
    assert matches_count == 63
Exemplo n.º 14
0
def test_should_match_only_digits():
    matches_count = matcher(r'\d', text_to_search)
    assert matches_count == 60
Exemplo n.º 15
0
def test_should_match_any_characters_except_digits():
    matches_count = matcher(r'\D', text_to_search)
    assert matches_count == 161
Exemplo n.º 16
0
def test_simple_should_match_exactly_social_number_with_score():
    matches_count = matcher(r'\d\d\d-\d\d\d-\d\d\d', text_to_search)
    assert matches_count == 3
Exemplo n.º 17
0
                    if line.startswith(rels):
                        pat = line
                        break
                    elif line.startswith(s + ':'):
                        pat = rels + line[len(s) + 1:]
                        break
                pats[f].append(pat)
        except IOError, inst:
            if f != files[0]:
                warn(
                    _("skipping unreadable ignore file '%s': %s\n") %
                    (f, inst.strerror))

    allpats = []
    [allpats.extend(patlist) for patlist in pats.values()]
    if not allpats:
        return util.never

    try:
        files, ignorefunc, anypats = (util.matcher(root,
                                                   inc=allpats,
                                                   src='.hgignore'))
    except util.Abort:
        # Re-raise an exception where the src is the right file
        for f, patlist in pats.items():
            files, ignorefunc, anypats = (util.matcher(root,
                                                       inc=patlist,
                                                       src=f))

    return ignorefunc
Exemplo n.º 18
0
def test_should_match_two_end():
    matches_count = matcher(r'end', sentence)
    assert matches_count == 2
Exemplo n.º 19
0
def test_should_match_two_Start():
    matches_count = matcher(r'Start', sentence)
    assert matches_count == 2
Exemplo n.º 20
0
def test_should_match_second_Ha_from_Haha_word_ignore_new_line_and_space_boundaries():
    matches_count = matcher(r'\BHa', text_to_search)
    assert matches_count == 1
Exemplo n.º 21
0
def test_should_match_any_no_space_no_tab_and_no_new_line_characters():
    matches_count = matcher(r'\S', text_to_search)
    assert matches_count == 186
Exemplo n.º 22
0
                        syntax = syntaxes[s]
                    except KeyError:
                        warn(_("%s: ignoring invalid syntax '%s'\n") % (f, s))
                    continue
                pat = syntax + line
                for s, rels in syntaxes.iteritems():
                    if line.startswith(rels):
                        pat = line
                        break
                    elif line.startswith(s + ":"):
                        pat = rels + line[len(s) + 1 :]
                        break
                pats[f].append(pat)
        except IOError, inst:
            if f != files[0]:
                warn(_("skipping unreadable ignore file '%s': %s\n") % (f, inst.strerror))

    allpats = []
    [allpats.extend(patlist) for patlist in pats.values()]
    if not allpats:
        return util.never

    try:
        files, ignorefunc, anypats = util.matcher(root, inc=allpats, src=".hgignore")
    except util.Abort:
        # Re-raise an exception where the src is the right file
        for f, patlist in pats.iteritems():
            files, ignorefunc, anypats = util.matcher(root, inc=patlist, src=f)

    return ignorefunc
Exemplo n.º 23
0
def test_should_match_new_line_Ha_and_after_space_Ha():
    matches_count = matcher(r'\bHa', text_to_search)
    assert matches_count == 2
Exemplo n.º 24
0
                    continue
                pat = syntax + line
                for s, rels in syntaxes.items():
                    if line.startswith(rels):
                        pat = line
                        break
                    elif line.startswith(s+':'):
                        pat = rels + line[len(s)+1:]
                        break
                pats[f].append(pat)
        except IOError, inst:
            if f != files[0]:
                warn(_("skipping unreadable ignore file '%s': %s\n") %
                     (f, inst.strerror))

    allpats = []
    [allpats.extend(patlist) for patlist in pats.values()]
    if not allpats:
        return util.never

    try:
        files, ignorefunc, anypats = (
            util.matcher(root, inc=allpats, src='.hgignore'))
    except util.Abort:
        # Re-raise an exception where the src is the right file
        for f, patlist in pats.items():
            files, ignorefunc, anypats = (
                util.matcher(root, inc=patlist, src=f))

    return ignorefunc
Exemplo n.º 25
0
def test_should_match_starts_with_Start():
    matches_count = matcher(r'^Start', sentence)
    assert matches_count == 1
Exemplo n.º 26
0
def test_should_match_abc():
    matches_count = matcher(r'abc', text_to_search)
    assert matches_count == 1
Exemplo n.º 27
0
def test_should_match_ends_with_end():
    matches_count = matcher(r'end$', sentence)
    assert matches_count == 1
Exemplo n.º 28
0
def test_should_match_ABC():
    matches_count = matcher(r'ABC', text_to_search)
    assert matches_count == 1
Exemplo n.º 29
0
def test_simple_should_match_social_number():
    matches_count = matcher(r'\d\d\d.\d\d\d.\d\d\d', text_to_search)
    assert matches_count == 5
Exemplo n.º 30
0
def test_should_match_url():
    matches_count = matcher(r'coreyms\.com', text_to_search)
    assert matches_count == 1
Exemplo n.º 31
0
def test_should_match_any_characters_except_new_lines():
    matches_count = matcher(r'.', text_to_search)
    assert matches_count == 204
Exemplo n.º 32
0
 def __init__(self, root, cwd, patterns, include, exclude, default):
     f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
                              None, default)
     _match.__init__(self, root, cwd, f, mf, ap)