diff --git a/tests/test_cpu_edge_cases.py b/tests/test_cpu_edge_cases.py index 8937a07..b5dd270 100644 --- a/tests/test_cpu_edge_cases.py +++ b/tests/test_cpu_edge_cases.py @@ -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.""" diff --git a/tests/test_data_transfer.py b/tests/test_data_transfer.py index 680c27c..40313b6 100644 --- a/tests/test_data_transfer.py +++ b/tests/test_data_transfer.py @@ -5,6 +5,8 @@ import pytest +from tiny8 import CPU + class TestLDI: """Test LDI (Load Immediate) instruction.""" @@ -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