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")
def test_char_from(): pattern = r.char_from("x]") assert re.fullmatch(pattern, "x") assert re.fullmatch(pattern, "]") assert not re.fullmatch(pattern, "foo")
def test_char_from_string_needing_escape(): assert r.char_from("^x-z]") == r"[]xz^-]"
def test_char_from_simple_string(): assert r.char_from("abcABC") == "[abcABC]"
def test_char_from_single_char(): assert r.char_from("X") == "(X)" assert r.char_from(".") == r"(\.)"
def test_char_from_empty_string(): assert r.char_from("") == "()"