Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/test_cpu_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def test_jmp_with_invalid_label(self):
with pytest.raises(KeyError, match="Label nonexistent_label not found"):
cpu.step()

def test_run_rebuilds_predecoded_when_missing_or_mismatched(self):
"""Test fast-path rebuilds predecoded list when missing or length mismatched."""
cpu = CPU(trace_enabled=False)
cpu.load_program([("NOP", ())])
cpu._predecoded = []
cpu.run(max_steps=10, show_progress=False)
assert cpu.step_count == 1
assert len(cpu._predecoded) == 1

def test_run_fast_path_not_implemented_instruction(self):
"""Test fast-path raises NotImplementedError for unknown instructions."""
cpu = CPU(trace_enabled=False)
cpu.load_program([("UNKNOWN_OPCODE", ())])
with pytest.raises(
NotImplementedError, match="Instruction UNKNOWN_OPCODE not implemented"
):
cpu.run(max_steps=10, show_progress=False)


class TestCPUProgramLoading:
"""Test CPU program loading and execution edge cases."""
Expand Down
20 changes: 20 additions & 0 deletions tests/test_data_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import pytest

from tiny8 import CPU


class TestLDI:
"""Test LDI (Load Immediate) instruction."""
Expand Down Expand Up @@ -306,3 +308,21 @@ def test_16bit_pointer_pair(self, cpu_with_program, helper):
""")
helper.assert_register(cpu, 17, 99)
helper.assert_memory(cpu, 0x0210, 99)


class TestSER:
"""Test SER (Set Register) instruction."""

def test_ser_basic(self, cpu_with_program, helper):
"""Test setting register to $FF (255)."""
cpu = cpu_with_program("""
ser r16
ser r25
""")
helper.assert_registers(cpu, {16: 0xFF, 25: 0xFF})

def test_ser_direct_call(self):
"""Test op_ser method directly."""
cpu = CPU()
cpu.op_ser(17)
assert cpu.read_reg(17) == 0xFF
Loading