Skip to content

Commit

Permalink
reorganised tests for unconditional jump instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomi-3-0 committed Oct 25, 2023
1 parent 7c93f16 commit 56dfc1b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,11 @@ func TestAssertEqualInstruction(t *testing.T) {
func TestJumpInstructions(t *testing.T) {

// relative jumps
t.Run("jmp rel 5", func(t *testing.T){
vm := defaultVirtualMachine()
t.Run("jmp rel", func(t *testing.T){
vm := defaultVirtualMachineWithCode("jmp rel [ap + 1] + [ap - 7];")

vm.Context.Pc = mem.MemoryAddress{SegmentIndex: 1, Offset: 4}
relAddr := uint64(5)
vm.Context.Pc = mem.MemoryAddress{SegmentIndex: 1, Offset: 3}
relAddr := uint64(10)
res := mem.MemoryValueFromInt(relAddr)

instruction := a.Instruction{
Expand All @@ -977,13 +977,13 @@ func TestJumpInstructions(t *testing.T) {
nextPc, err := vm.updatePc(&instruction, nil, nil, &res)

require.NoError(t, err)
assert.Equal(t, mem.MemoryAddress{SegmentIndex: 1, Offset: 9}, nextPc)
assert.Equal(t, mem.MemoryAddress{SegmentIndex: 1, Offset: 3 + relAddr}, nextPc)

})

// absolute jumps
t.Run("jmp abs 123", func(t *testing.T) {
vm := defaultVirtualMachine()
vm := defaultVirtualMachineWithCode("jmp abs 123;")

vm.Context.Pc = mem.MemoryAddress{SegmentIndex: 0, Offset: 3}
jmpAddr := uint64(123)
Expand Down

0 comments on commit 56dfc1b

Please sign in to comment.