aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer/pointer_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 14:59:14 +0200
committerJulien Dessaux2021-09-23 14:59:14 +0200
commitf86b5724e530ec86eed04ebeb257293244f4be69 (patch)
tree0ceaddd9f08229899eb94f7134a048c5b36d9ba4 /pkg/pointer/pointer_test.go
parentEach pointer needs its own stack, merging the two packages to avoid a circula... (diff)
downloadgofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.tar.gz
gofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.tar.bz2
gofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.zip
Moved the character execution's to the pointer in order to handle the k command
Diffstat (limited to 'pkg/pointer/pointer_test.go')
-rw-r--r--pkg/pointer/pointer_test.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/pkg/pointer/pointer_test.go b/pkg/pointer/pointer_test.go
index 4885d6b..aa007fe 100644
--- a/pkg/pointer/pointer_test.go
+++ b/pkg/pointer/pointer_test.go
@@ -9,7 +9,7 @@ import (
)
func TestNewPointer(t *testing.T) {
- require.Equal(t, NewPointer(), &Pointer{dx: 1, ss: NewStackStack()})
+ require.Equal(t, NewPointer(), &Pointer{dx: 1, Ss: NewStackStack()})
}
func TestSplit(t *testing.T) {
@@ -23,8 +23,8 @@ func TestSplit(t *testing.T) {
// We check that p2 is a real copy
p.Step(*f)
p2.Step(*f)
- require.Equal(t, &Pointer{x: 1, y: 0, dx: 1, ss: NewStackStack()}, p)
- require.Equal(t, &Pointer{x: 1, y: 0, dx: 1, ss: NewStackStack()}, p2)
+ require.Equal(t, &Pointer{x: 1, y: 0, dx: 1, Ss: NewStackStack()}, p)
+ require.Equal(t, &Pointer{x: 1, y: 0, dx: 1, Ss: NewStackStack()}, p2)
}
func TestStep(t *testing.T) { // Step is thoroughly tested in the field package
@@ -51,6 +51,17 @@ func TestGet(t *testing.T) {
require.Equal(t, int('@'), v)
}
+func TestStepAndGet(t *testing.T) {
+ // File of one char
+ file, err := os.Open("../field/test_data/minimal.b98")
+ require.NoError(t, err, "Failed to open file")
+ defer file.Close()
+ f, err := field.Load(file)
+ p := NewPointer()
+ v := p.StepAndGet(*f)
+ require.Equal(t, int('@'), v)
+}
+
func TestSet(t *testing.T) {
p := NewPointer()
p.Set(3, 14)
@@ -93,8 +104,8 @@ func TestRedirect(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
p := NewPointer()
p.RedirectTo(3, 14)
- p.ss.Push(2)
- p.ss.Push(7)
+ p.Ss.Push(2)
+ p.Ss.Push(7)
v := p.Redirect(int(tc.input))
require.Equal(t, true, v)
require.Equal(t, tc.expectedDx, p.dx, "Invalid dx value")