from __future__ import annotations

from elmpythonator.adapter.adapter import Adapter


def test_can_auto_format_with_headers_includes_data_length_byte() -> None:
    adapter = Adapter(name="test")
    adapter.can_auto_format = True
    adapter.auto_segmentation_rx = False
    adapter.print_headers = True
    adapter.spaces = False

    # Single-frame response: 0x06 data bytes follow, then one padding byte.
    output = adapter.format_received_bytes(0x7E8, [0x06, 0x41, 0x00, 0x98, 0x1B, 0x80, 0x03, 0x55])

    assert output == "7E8064100981B8003"


def test_can_auto_format_without_headers_omits_data_length_byte() -> None:
    adapter = Adapter(name="test")
    adapter.can_auto_format = True
    adapter.auto_segmentation_rx = False
    adapter.print_headers = False
    adapter.spaces = False

    output = adapter.format_received_bytes(0x7E8, [0x06, 0x41, 0x00, 0x98, 0x1B, 0x80, 0x03, 0x55])

    assert output == "4100981B8003"
