Skip to content

Commit

Permalink
Add vm_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenhombre committed Jul 30, 2023
1 parent 1cad80c commit 4da5be6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions vm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"testing"
)

func TestVM(t *testing.T) {
C := func(i value) Entry { return constantEntry(i) }
Op := func(o opcode) Entry { return opEntry(o) }
// Make our stack
s := newStack()
// Create code to push 1 and 2 on the stack, add them, print the
// result, and return:
c := newChunk(C(1), C(2), Op(op_add), Op(op_ret))
// Run the code in a new VM:
vm := newVM(c)
// Run the VM
if vm.run(s) != 3 {
t.Error("vm should return 3")
}
}

0 comments on commit 4da5be6

Please sign in to comment.