From da804769c659ac290fa00d34123ffe50101d38d3 Mon Sep 17 00:00:00 2001 From: Jairinho Date: Wed, 23 Feb 2022 16:28:17 -0300 Subject: [PATCH] some checks to ensure stack consistency --- chip8/stack_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/chip8/stack_test.go b/chip8/stack_test.go index f0fd33b..77313de 100644 --- a/chip8/stack_test.go +++ b/chip8/stack_test.go @@ -18,6 +18,17 @@ func TestEmulator_StackPush(t *testing.T) { assert.Equal(t, chip8.StackAddress+2, emulator.SP) } +func TestEmulator_StackPush_Overflow(t *testing.T) { + emulator := chip8.NewEmulator() + + defer func() { + assert.Equal(t, "chip8: stack overflow", recover()) + }() + + emulator.SP = chip8.StackAddress + chip8.StackSize*2 + emulator.StackPush() +} + func TestEmulator_StackPop(t *testing.T) { emulator := chip8.NewEmulator() @@ -29,3 +40,13 @@ func TestEmulator_StackPop(t *testing.T) { assert.Equal(t, uint16(0xEEFF), emulator.PC) assert.Equal(t, chip8.StackAddress+30, emulator.SP) } + +func TestEmulator_StackPop_Empty(t *testing.T) { + emulator := chip8.NewEmulator() + + defer func() { + assert.Equal(t, "chip8: nothing to pop from stack", recover()) + }() + + emulator.StackPop() +}