diff options
author | Julien Dessaux | 2021-09-20 01:23:39 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-20 10:33:10 +0200 |
commit | 46170dd5b70588c9b1c6f4aa5aaea2649d8c74f0 (patch) | |
tree | 1e4ac74fc7e3ec44b22d50ceb9564e336cc3d89f /pkg/pointer/pointer_test.go | |
parent | Refactoring (diff) | |
download | gofunge98-46170dd5b70588c9b1c6f4aa5aaea2649d8c74f0.tar.gz gofunge98-46170dd5b70588c9b1c6f4aa5aaea2649d8c74f0.tar.bz2 gofunge98-46170dd5b70588c9b1c6f4aa5aaea2649d8c74f0.zip |
Began implementing the Instruction Pointer
Diffstat (limited to 'pkg/pointer/pointer_test.go')
-rw-r--r-- | pkg/pointer/pointer_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pkg/pointer/pointer_test.go b/pkg/pointer/pointer_test.go new file mode 100644 index 0000000..3a77507 --- /dev/null +++ b/pkg/pointer/pointer_test.go @@ -0,0 +1,41 @@ +package pointer + +import ( + "os" + "testing" + + "git.adyxax.org/adyxax/gofunge/pkg/field" + "github.com/stretchr/testify/require" +) + +func TestNewPointer(t *testing.T) { + require.Equal(t, NewPointer(), &Pointer{delta: &Delta{1, 0}}) +} + +func TestForkPointer(t *testing.T) { + file, err := os.Open("../field/test_data/hello.b98") + require.NoError(t, err, "Failed to open file") + defer file.Close() + f, err := field.Load(file) + require.NoError(t, err) + p := NewPointer() + p2 := p.ForkPointer() + // We check that p2 is a real copy + p.Step(*f) + p2.Step(*f) + require.Equal(t, p, &Pointer{x: 1, y: 0, delta: &Delta{1, 0}}) + require.Equal(t, p2, &Pointer{x: 1, y: 0, delta: &Delta{1, 0}}) +} + +func TestStep(t *testing.T) { // Step is thoroughly tested in the field package + defaultPointer := NewPointer() + // 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) + require.NoError(t, err) + p := NewPointer() + p.Step(*f) + require.Equal(t, defaultPointer, p) +} |