# SPDX-FileCopyrightText: © 2026 Joe T. Sylve, Ph.D. <joe.sylve@gmail.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

"""Integration tests for LTspice decryption.

Test data was generated by LTspice from the same minimal .subckt model
used in the PSpice tests.
"""

from __future__ import annotations

from pathlib import Path

from spice_crypt import decrypt_stream
from spice_crypt.ltspice.decrypt import LTspiceFileParser
from tests.conftest import PLAINTEXT_BODY, extract_body

DATA_DIR = Path(__file__).parent / "data"


class TestLTspiceDecryption:
    """Verify decryption of LTspice-encrypted files."""

    def test_decrypt_ltspice(self):
        content, _ = decrypt_stream(str(DATA_DIR / "ltspice.lib"))
        assert extract_body(content) == PLAINTEXT_BODY


class TestLTspiceFileParser:
    """Test the LTspiceFileParser class directly."""

    def test_parser_stream(self):
        with open(DATA_DIR / "ltspice.lib") as f:
            parser = LTspiceFileParser(f)
            chunks = list(parser.decrypt_stream())
        text = b"".join(chunks).decode("utf-8", "replace")
        assert "R1 1 2 1k" in text
