import pytest

from test.stack.test_helpers import (
    count_defs_refs,
    resolve_symbol,
    setup_stack_resolution,
)


@pytest.mark.blends_test_group("functional")
def test_multiple_bare_params() -> None:
    view, record = setup_stack_resolution("case_multiple_params.py")
    for symbol in ["a", "b", "c"]:
        defs, refs = count_defs_refs(view, symbol)
        result = resolve_symbol(view, record, symbol)
        assert defs == 1, f"Expected 1 def of '{symbol}', got {defs}"
        assert refs == 1, f"Expected 1 ref to '{symbol}', got {refs}"
        assert len(result) == 1, f"Expected bare param '{symbol}' to resolve, got {len(result)}"


@pytest.mark.blends_test_group("functional")
def test_self_reference_in_method() -> None:
    view, record = setup_stack_resolution("case_self_reference.py")
    defs, refs = count_defs_refs(view, "self")
    result = resolve_symbol(view, record, "self")
    assert defs == 1, f"Expected 1 def of 'self', got {defs}"
    assert refs >= 1, f"Expected at least 1 ref to 'self', got {refs}"
    assert len(result) == 1, (
        f"Expected 'self' parameter to resolve to its definition, got {len(result)}"
    )
