Skip to content

Commit

Permalink
Instruction size test
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Jul 29, 2024
1 parent ac02039 commit b09946a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cmd/bfg/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io"
"testing"
)

Expand Down Expand Up @@ -53,8 +52,7 @@ func TestInputReader(t *testing.T) {
} else if err == nil && v.err {
t.Error("Error was expected")
} else if !v.err {
_, ok := buff.(io.ByteReader)
if !ok {
if buff == nil {
t.Error("no reader returned")
}
}
Expand Down
16 changes: 16 additions & 0 deletions parser/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"testing"
"unsafe"
)

var opName = map[Opcode]string{
Expand All @@ -25,6 +26,21 @@ func (inst Instruction) String() string {
return fmt.Sprintf("%s:%v", opName[inst.operator], inst.operand)
}

func TestInstructionSize(t *testing.T) {
sizes := []uintptr{2, 4, 8, 16, 32, 64, 128}
ok := false
got := unsafe.Sizeof(NewInstruction('-'))
for _, s := range sizes {
if s == got {
ok = true
break
}
}
if !ok {
t.Errorf("size not in array: got %v", got)
}
}

func TestNewInstruction(t *testing.T) {
sourceCode := "g><+-.,[]"
program := []Instruction{
Expand Down

0 comments on commit b09946a

Please sign in to comment.