import pytest
from ecu_framework.lin.base import LinFrame


@pytest.mark.unit
def test_linframe_accepts_valid_ranges(record_property: "pytest.RecordProperty"):  # type: ignore[name-defined]
    f = LinFrame(id=0x3F, data=bytes([0] * 8))
    record_property("valid_id", f"0x{f.id:02X}")
    record_property("data_len", len(f.data))
    assert f.id == 0x3F and len(f.data) == 8


@pytest.mark.unit
@pytest.mark.parametrize("bad_id", [-1, 0x40])
def test_linframe_invalid_id_raises(bad_id, record_property: "pytest.RecordProperty"):  # type: ignore[name-defined]
    record_property("bad_id", bad_id)
    with pytest.raises(ValueError):
        LinFrame(id=bad_id, data=b"\x00")


@pytest.mark.unit
def test_linframe_too_long_raises(record_property: "pytest.RecordProperty"):  # type: ignore[name-defined]
    record_property("data_len", 9)
    with pytest.raises(ValueError):
        LinFrame(id=0x01, data=bytes(range(9)))
