aboutsummaryrefslogtreecommitdiff
path: root/pkg/interpreter/interpreter_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 11:45:49 +0200
committerJulien Dessaux2021-09-23 11:45:49 +0200
commit759ee2aa10323d1960405c93f7cd4cf6d383ae7a (patch)
tree87648b4811b0264f1b54c454ed2569abe1abee94 /pkg/interpreter/interpreter_test.go
parentBegan coding the interpreter (only manages the minimal example for now!) (diff)
downloadgofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.tar.gz
gofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.tar.bz2
gofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.zip
Each pointer needs its own stack, merging the two packages to avoid a circular dependency
Diffstat (limited to 'pkg/interpreter/interpreter_test.go')
-rw-r--r--pkg/interpreter/interpreter_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/pkg/interpreter/interpreter_test.go b/pkg/interpreter/interpreter_test.go
new file mode 100644
index 0000000..ff633a2
--- /dev/null
+++ b/pkg/interpreter/interpreter_test.go
@@ -0,0 +1,50 @@
+package interpreter
+
+import (
+ "os"
+ "testing"
+
+ "git.adyxax.org/adyxax/gofunge/pkg/field"
+ "git.adyxax.org/adyxax/gofunge/pkg/pointer"
+ "github.com/stretchr/testify/require"
+)
+
+func TestRun(t *testing.T) {
+ file, err := os.Open("../field/test_data/minimal.b98")
+ require.NoError(t, err)
+ defer file.Close()
+ f, err := field.Load(file)
+ require.NoError(t, err)
+ NewInterpreter(f, pointer.NewPointer()).Run()
+}
+
+func TestStep(t *testing.T) {
+ testCases := []struct {
+ name string
+ filename string
+ pointer *pointer.Pointer
+ expectedField *field.Field
+ expectedPointer *pointer.Pointer
+ }{
+ {"minimal", "../field/test_data/minimal.b98", nil, nil, nil},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ file, err := os.Open(tc.filename)
+ require.NoError(t, err)
+ defer file.Close()
+ f, err := field.Load(file)
+ require.NoError(t, err)
+ if tc.pointer == nil {
+ tc.pointer = pointer.NewPointer()
+ }
+ NewInterpreter(f, tc.pointer).Step()
+ if tc.expectedField != nil {
+ require.Equal(t, tc.expectedField, f)
+ }
+ if tc.expectedPointer != nil {
+ require.Equal(t, tc.expectedPointer, tc.pointer)
+ }
+ })
+ }
+}