def test_match_not_equals() -> None: with match(Some(42)) as case: if case(Some(4)): assert False if case._: assert True
def test_match_instance() -> None: with match(42) as case: for value in case(42): assert value == 42 break else: assert False
def test_match_isinstance() -> None: with match(B()) as case: for _ in case(A): assert True break else: assert False
def test_not_match_isinstance() -> None: with match(A()) as case: if case(B): assert False if case._: assert True
def test_not_match_type() -> None: with match(42) as case: if case(float): assert False if case._: assert True
def test_match_type() -> None: with match(42) as case: for value in case(int): assert value == 42 break else: assert False
def test_active_pattern_not_matches() -> None: text = "abc" with match(text) as case: for _ in case(ParseInteger): assert False if case._: assert True
def test_active_pattern_matches() -> None: text = "42" with match(text) as case: for value in case(ParseInteger): assert value == int(text) if case._: assert False
def test_not_match_instance() -> None: x = 42 with match(x) as case: if case(43): assert False if case._: assert True
def test_option_some_match(): xs = Some(42) with match(xs) as case: for x in case(Some[int]): assert x == 42 while case.default(): assert False
def test_result_match_error(): xs: Result[int, str] = Error("err") with match(xs) as case: for err in case(Error[int, str]): assert err == "err" break else: assert False
def test_result_match_ok(): xs: Result[int, str] = Ok(42) with match(xs) as case: for x in case(Ok[int, str]): assert x == 42 break else: assert False
def test_match_multiple_only_matches_first() -> None: with match("expression") as case: for value in case(str): assert value == "expression" for value in case(str): assert False if case._: assert False
def test_choice_choice1of2(): xs: Choice2[int, str] = Choice1of2(42) assert isinstance(xs, Choice) assert isinstance(xs, Choice2) with match(xs) as case: for x in Choice1of2.match(case): assert x == 42 break else:
def test_option_none_match(): xs = Nothing with match(xs) as case: for _ in case(Some[int]): assert False while case(Nothing): assert True while case.default(): assert False
def test_match_multiple_cases() -> None: with match("expression") as case: while case("rxpy"): assert False for value in case(str): assert value == "expression" for value in case(float): assert False if case._: assert False
def matcher(value: str) -> Option[str]: with match(value) as case: while case("rxpy"): assert False for value in case(str): assert value == "expression" return Some(value) for value in case("aioreactive"): assert False if case._: assert False return Nothing
def test_match_destructure() -> None: xs: FrozenList[int] = FrozenList.empty().cons(42) with match(xs) as case: for (head, *_) in case(FrozenList[int]): assert head == 42
def test_default_matches() -> None: with match(42) as case: for value in case._: assert value == 42
def test_default_falsy_matches() -> None: with match(None) as case: if case._: assert True else: assert False
def test_match_generic_matches() -> None: xs = [1, 2, 3] with match(xs) as case: for x in case(List[int]): assert x == xs