def test_match_components():
    """Test matching cases with return values as components."""
    match_case_tuples = (
        (1, rx.text("first value")),
        (2, 3, rx.text("second value")),
        ([1, 2], rx.text("third value")),
        ("random", rx.text("fourth value")),
        ({"foo": "bar"}, rx.text("fifth value")),
        (MatchState.num + 1, rx.text("sixth value")),
        rx.text("default value"),
    )
    match_comp = Match.create(MatchState.value, *match_case_tuples)

    assert isinstance(match_comp, Component)
    match_dict = match_comp.render()
    assert match_dict["name"] == "Fragment"

    [match_child] = match_dict["children"]

    assert match_child["name"] == "match"
    assert str(match_child["cond"]) == f"{MatchState.get_name()}.value"

    match_cases = match_child["match_cases"]
    assert len(match_cases) == 6

    assert match_cases[0][0]._js_expr == "1"
    assert match_cases[0][0]._var_type is int
    first_return_value_render = match_cases[0][1]
    assert first_return_value_render["name"] == "RadixThemesText"
    assert first_return_value_render["children"][0]["contents"] == '"first value"'

    assert match_cases[1][0]._js_expr == "2"
    assert match_cases[1][0]._var_type is int
    assert match_cases[1][1]._js_expr == "3"
    assert match_cases[1][1]._var_type is int
    second_return_value_render = match_cases[1][2]
    assert second_return_value_render["name"] == "RadixThemesText"
    assert second_return_value_render["children"][0]["contents"] == '"second value"'

    assert match_cases[2][0]._js_expr == "[1, 2]"
    assert match_cases[2][0]._var_type == Sequence[int]
    third_return_value_render = match_cases[2][1]
    assert third_return_value_render["name"] == "RadixThemesText"
    assert third_return_value_render["children"][0]["contents"] == '"third value"'

    assert match_cases[3][0]._js_expr == '"random"'
    assert match_cases[3][0]._var_type is str
    fourth_return_value_render = match_cases[3][1]
    assert fourth_return_value_render["name"] == "RadixThemesText"
    assert fourth_return_value_render["children"][0]["contents"] == '"fourth value"'

    assert match_cases[4][0]._js_expr == '({ ["foo"] : "bar" })'
    assert match_cases[4][0]._var_type == Mapping[str, str]
    fifth_return_value_render = match_cases[4][1]
    assert fifth_return_value_render["name"] == "RadixThemesText"
    assert fifth_return_value_render["children"][0]["contents"] == '"fifth value"'

    assert match_cases[5][0]._js_expr == f"({MatchState.get_name()}.num + 1)"
    assert match_cases[5][0]._var_type is int
    fifth_return_value_render = match_cases[5][1]
    assert fifth_return_value_render["name"] == "RadixThemesText"
    assert fifth_return_value_render["children"][0]["contents"] == '"sixth value"'

    default = match_child["default"]

    assert default["name"] == "RadixThemesText"
    assert default["children"][0]["contents"] == '"default value"'
Test matching cases with return values as components.
tests/units/components/core/test_match.py