def test_bind_repeated(): assert match((0, 0, 1, 1), (bind.zero, bind.zero, bind.one, bind.one)) assert not match((0, 1), (bind.value, bind.value))
def match_basic(value): if match(value, None): return 'case-1' elif match(value, True): return 'case-2' elif match(value, False): return 'case-3' elif match(value, -100): return 'case-4' elif match(value, 1.234): return 'case-5' elif match(value, 12345678901234567890): return 'case-6' elif match(value, complex(1, 2)): return 'case-7' elif match(value, str('alpha')): return 'case-8' elif match(value, bytes(b'beta')): return 'case-9' elif match(value, (1, 2, 3, 4)): return 'case-15' elif match(value, [bind.first, bind.second, bind.third]): return 'case-11' elif match(value, like('^abc..abc$')): return 'case-12' elif match(value, like(lambda val: val % 17 == 0)): return 'case-13' elif match(value, Point(0, 0, 0, 0)): return 'case-14' elif match(value, [1, 2, 3, 4]): return 'case-16' elif match(value, (0, [1, (2, [3, (4, [5])])])): return 'case-17' elif match(value, tuple): return 'case-10' elif match(value, like(lambda val: val % 19 == 0)): return 'case-18' elif match(value, object): return 'case-19' else: raise Exception('no match')
def test_bind_any(): assert match([0, 1, 2], [bind.any, bind.any, bind.any])
def test_bound(): match(5, bind.value) assert bound.value == 5
def test_bind_result(): if match(0, bind._push): return 'zero' else: return 'nonzero'