Exemplo n.º 1
0
def test_upTo():
    res=ExpressiveRegex()\
    .upTo(4).digit\
    .toRegexString()
    assert res=='\\d{,4}'
    res=ExpressiveRegex()\
    .upTo(1).digit\
    .toRegexString()
    assert res=='\\d?'
Exemplo n.º 2
0
def test_atLeast():
    res=ExpressiveRegex()\
    .atLeast(4).digit\
    .toRegexString()
    assert res=='\\d{4,}'
    res=ExpressiveRegex()\
    .atLeast(0).digit\
    .toRegexString()
    assert res=='\\d*'
    res=ExpressiveRegex()\
    .atLeast(1).digit\
    .toRegexString()
    assert res=='\\d+'
Exemplo n.º 3
0
def test_between():
    res=ExpressiveRegex()\
    .between(2,4).digit\
    .toRegexString()
    assert res=='\\d{2,4}'
    res=ExpressiveRegex()\
    .between(0,1).digit\
    .toRegexString()
    assert res=='\\d?'
    res=ExpressiveRegex()\
    .between(0,4).digit\
    .toRegexString()
    assert res=='\\d{,4}'
Exemplo n.º 4
0
def test_anythingButChars():
    expression = "".join(
        random.choices(string.ascii_letters,
                       k=random.randint(1, len(string.ascii_letters))))
    res=ExpressiveRegex()\
        .anythingButChars(expression)\
        .toRegexString()
    assert res == '[^' + expression + ']'
Exemplo n.º 5
0
def test_setOfLiterals():
    res=ExpressiveRegex()\
    .setOfLiterals\
    .char('-')\
    .range(1,4)\
    .anyOfChars('dfs')\
    .end()\
    .toRegexString()
    assert res=='[\\-1-4dfs]'
Exemplo n.º 6
0
def test_char_and_rawChar():
    for i in string.ascii_letters:
        res=ExpressiveRegex()\
        .char(i)\
        .toRegexString()
        assert res == i
        res=ExpressiveRegex()\
        .rawChar(i)\
        .toRegexString()
        assert res == i
    for i in string.digits:
        res=ExpressiveRegex()\
        .char(i)\
        .toRegexString()
        assert res == i
        res=ExpressiveRegex()\
        .rawChar(i)\
        .toRegexString()
        assert res == i
    for i in specialChars:
        res=ExpressiveRegex()\
        .char(i)\
        .toRegexString()
        assert res == '\\' + i
        res=ExpressiveRegex()\
        .rawChar(i)\
        .toRegexString()
        assert res == i
Exemplo n.º 7
0
def test_string_and_rawString():
    expression = "".join(
        random.choices(string.ascii_letters,
                       k=random.randint(1, len(string.ascii_letters))))
    res=ExpressiveRegex()\
        .string(expression)\
        .toRegexString()
    assert res == expression
    res=ExpressiveRegex()\
        .rawString(expression)\
        .toRegexString()
    assert res == expression
    expression = "".join(
        random.choices(specialChars, k=random.randint(1, len(specialChars))))
    fix_expression = "".join(('\\' + i for i in expression))
    res=ExpressiveRegex()\
        .string(expression)\
        .toRegexString()
    assert res == fix_expression
    res=ExpressiveRegex()\
        .rawString(expression)\
        .toRegexString()
    assert res == expression
Exemplo n.º 8
0
def test_oneOrMoreLazy():
    res=ExpressiveRegex()\
    .oneOrMoreLazy.digit\
    .toRegexString()
    assert res=='\\d+?'
Exemplo n.º 9
0
def test_optional():
    res=ExpressiveRegex()\
    .optional.digit\
    .toRegexString()
    assert res=='\\d?'
Exemplo n.º 10
0
def test_space():
    res=ExpressiveRegex()\
    .space\
    .toRegexString()
    assert res == ' '
Exemplo n.º 11
0
def test_nonWhitespaceChar():
    res=ExpressiveRegex()\
    .nonWhitespaceChar\
    .toRegexString()
    assert res == '\\S'
Exemplo n.º 12
0
def test_whitespaceChar():
    res=ExpressiveRegex()\
    .whitespaceChar\
    .toRegexString()
    assert res == '\\s'
Exemplo n.º 13
0
def test_nonWord():
    res=ExpressiveRegex()\
    .nonWord\
    .toRegexString()
    assert res == '\\W'
Exemplo n.º 14
0
def test_word():
    res=ExpressiveRegex()\
    .word\
    .toRegexString()
    assert res == '\\w'
Exemplo n.º 15
0
def test_nonDigit():
    res=ExpressiveRegex()\
    .nonDigit\
    .toRegexString()
    assert res == '\\D'
Exemplo n.º 16
0
def test_digit():
    res=ExpressiveRegex()\
    .digit\
    .toRegexString()
    assert res == '\\d'
Exemplo n.º 17
0
def test_exactly():
    res=ExpressiveRegex()\
    .exactly(4).digit\
    .toRegexString()
    assert res=='\\d{4}'
Exemplo n.º 18
0
def test_betweenLazy():
    res=ExpressiveRegex()\
    .betweenLazy(2,4).digit\
    .toRegexString()
    assert res=='\\d{2,4}?'
Exemplo n.º 19
0
def test_newline():
    res=ExpressiveRegex()\
    .newline\
    .toRegexString()
    assert res == '\\n'
Exemplo n.º 20
0
def test_anythingButRange():
    exp=ExpressiveRegex()\
        .anythingButRange(0,9)\
        .toRegex()
    for d in string.digits:
        res = exp.search(d)
        assert res is None
    exclud = [2]
    exp=ExpressiveRegex()\
        .anythingButRange(0,9, exclude=exclud)\
        .toRegex()
    for d in string.digits:
        res = exp.search(d)
        if int(d) in exclud:
            assert res is not None
        else:
            assert res is None
    exclud = [2, 4]
    exp=ExpressiveRegex()\
        .anythingButRange(0,9, exclude=exclud)\
        .toRegex()
    exclud = set(exclud)
    for d in string.digits:
        res = exp.search(d)
        if int(d) in exclud:
            assert res is not None
        else:
            assert res is None
    exp=ExpressiveRegex()\
        .anythingButRange('a','z')\
        .toRegex()
    for d in string.ascii_lowercase:
        res = exp.search(d)
        assert res is None
    exclud = 'a'
    exp=ExpressiveRegex()\
        .anythingButRange('a','z', exclude=exclud)\
        .toRegex()
    exclud = set(exclud)
    for d in string.ascii_lowercase:
        res = exp.search(d)
        if d in exclud:
            assert res is not None
        else:
            assert res is None
    exclud = 'abz'
    exp=ExpressiveRegex()\
        .anythingButRange('a','z', exclude=exclud)\
        .toRegex()
    exclud = set(exclud)
    for d in string.ascii_lowercase:
        res = exp.search(d)
        if d in exclud:
            assert res is not None
        else:
            assert res is None
    exclud = 'a'
    exp=ExpressiveRegex()\
        .anythingButRange('a','z', exclude=exclud)\
        .toRegex()
    exclud = set(exclud)
    for d in string.ascii_lowercase:
        res = exp.search(d)
        if d in exclud:
            assert res is not None
        else:
            assert res is None
    exclud = 'AFX'
    exp=ExpressiveRegex()\
        .anythingButRange('A','Z', exclude=exclud)\
        .toRegex()
    exclud = set(exclud)
    for d in string.ascii_uppercase:
        res = exp.search(d)
        if d in exclud:
            assert res is not None
        else:
            assert res is None
Exemplo n.º 21
0
def test_carriageReturn():
    res=ExpressiveRegex()\
    .carriageReturn\
    .toRegexString()
    assert res == '\\r'
Exemplo n.º 22
0
def test_tab():
    res=ExpressiveRegex()\
    .tab\
    .toRegexString()
    assert res == '\\t'
Exemplo n.º 23
0
def test_zeroOrMore():
    res=ExpressiveRegex()\
    .zeroOrMore.digit\
    .toRegexString()
    assert res=='\\d*'
Exemplo n.º 24
0
def test_anyChar():
    res=ExpressiveRegex()\
    .anyChar\
    .toRegexString()
    assert res == '.'