예제 #1
0
def test_number():
    int_pattern = r.seq(r.opt(r.alt(r.quote("+"), r.quote("-"))),
                        r.repeat(1, None, r.char_from("0123456789")))
    num_pattern = r.seq(int_pattern,
                        r.opt(r.seq(r.quote("."),
                                    r.opt(int_pattern))))
    number = re.compile(num_pattern)

    assert not number.fullmatch("foo")
    assert not number.fullmatch("+")
    assert number.fullmatch("0")
    assert number.fullmatch("-42")
    assert number.fullmatch("3.")
    assert number.fullmatch("3.14")
예제 #2
0
def test_char_from():
    pattern = r.char_from("x]")
    assert re.fullmatch(pattern, "x")
    assert re.fullmatch(pattern, "]")
    assert not re.fullmatch(pattern, "foo")
예제 #3
0
def test_char_from_string_needing_escape():
    assert r.char_from("^x-z]") == r"[]xz^-]"
예제 #4
0
def test_char_from_simple_string():
    assert r.char_from("abcABC") == "[abcABC]"
예제 #5
0
def test_char_from_single_char():
    assert r.char_from("X") == "(X)"
    assert r.char_from(".") == r"(\.)"
예제 #6
0
def test_char_from_empty_string():
    assert r.char_from("") == "()"