def test_merges_multiple_subtracts(): x = rd.star(rd.char(b'012')) y = rd.star(rd.char(b'0')) z = rd.star(rd.char(b'1')) t = rd.subtract(rd.subtract(x, y), z) assert t is rd.subtract(x, rd.union(y, z)) t = rd.subtract(x, rd.subtract(y, z)) assert t.nullable assert isinstance(t, rd.Union)
def test_bounds_propagate_through_subtraction(): x = rd.star(rd.char(b'\0\1')) y = rd.literal(b'\0\0\0\1') z = rd.subtract(x, y) b = rd.bounded(z, 10) assert isinstance(b, rd.Subtraction) assert isinstance(b.left, rd.Bounded)
def symdiff(x, y): return rd.union(rd.subtract(x, y), rd.subtract(y, x))
def test_infinite_regex_have_more_than_one_solution(reg): assume(rd.is_infinite(reg)) x = rd.subtract(reg, rd.literal(rd.lexmin(reg))) assert rd.has_matches(x)
def test_valid_starts_of_subtraction(): x = rd.star(rd.char(b'\0\1')) y = rd.char(b'\1') z = rd.subtract(x, y) assert rd.valid_starts(z) == pset([0, 1])
def test_subtraction_from_epsilon_checks_nullability(): assert rd.subtract(rd.Epsilon, rd.char(0)) is rd.Epsilon assert rd.subtract(rd.Epsilon, rd.star(rd.char(0))) is rd.Empty
def test_subtraction_from_empty_is_empty(): x = rd.char(0) assert rd.subtract(rd.Empty, x) is rd.Empty
def test_empty_subtraction_is_identity(): x = rd.char(0) assert rd.subtract(x, rd.Empty) is x
def test_self_subtraction_is_empty(): x = rd.char(0) assert rd.subtract(x, x) is rd.Empty
@given(regex()) def test_characters_in_same_class_produce_equivalent_expressions(re): assume(rd.has_matches(re)) classes = rd.character_classes(re) assume(any(len(cs) > 1 for cs in classes)) for cs in classes: if len(cs) > 1: derivs = [rd.derivative(re, c) for c in cs] for a in derivs: for b in derivs: assert rd.equivalent(a, b) @example(rd.star(rd.char(b'0'))) @example(rd.subtract(rd.star(rd.char(b'0')), rd.char(b'0'))) @given(regex()) def test_infinite_regex_have_more_than_one_solution(reg): assume(rd.is_infinite(reg)) x = rd.subtract(reg, rd.literal(rd.lexmin(reg))) assert rd.has_matches(x) @example(rd.concatenate(rd.star(rd.char(b'\0')), rd.char(b'\1'))) @example(rd.union(rd.char(b'\0'), rd.star(rd.literal(b'\0\0')))) @example(rd.star(rd.char(0))) @given(regex()) def test_decompilation(re): assume(rd.has_matches(re)) dfa = rd.build_dfa(re) rewritten = rd.decompile_dfa(*dfa)