vise/go/vm/vm_test.go

109 lines
2.1 KiB
Go
Raw Normal View History

2023-03-31 11:52:04 +02:00
package vm
import (
"testing"
)
2023-04-02 13:12:06 +02:00
func TestParseNoArg(t *testing.T) {
b := NewLine(nil, HALT, nil, nil, nil)
b, err := ParseHalt(b)
2023-03-31 11:52:04 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-03-31 11:52:04 +02:00
}
}
2023-03-31 11:59:55 +02:00
2023-04-02 13:12:06 +02:00
func TestParseSym(t *testing.T) {
b := NewLine(nil, MAP, []string{"baz"}, nil, nil)
sym, b, err := ParseMap(b)
2023-03-31 11:59:55 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-03-31 11:59:55 +02:00
}
2023-04-02 13:12:06 +02:00
if sym != "baz" {
t.Fatalf("expected sym baz, got %v", sym)
2023-03-31 11:59:55 +02:00
}
2023-04-02 13:12:06 +02:00
b = NewLine(nil, RELOAD, []string{"xyzzy"}, nil, nil)
sym, b, err = ParseReload(b)
2023-03-31 11:59:55 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-03-31 11:59:55 +02:00
}
2023-04-02 13:12:06 +02:00
if sym != "xyzzy" {
t.Fatalf("expected sym xyzzy, got %v", sym)
2023-03-31 11:59:55 +02:00
}
2023-03-31 16:24:29 +02:00
2023-04-02 13:12:06 +02:00
b = NewLine(nil, MOVE, []string{"plugh"}, nil, nil)
sym, b, err = ParseMove(b)
2023-03-31 16:24:29 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
}
if sym != "plugh" {
t.Fatalf("expected sym plugh, got %v", sym)
2023-03-31 16:24:29 +02:00
}
}
2023-04-02 13:12:06 +02:00
func TestParseTwoSym(t *testing.T) {
b := NewLine(nil, INCMP, []string{"foo", "bar"}, nil, nil)
one, two, b, err := ParseInCmp(b)
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
}
2023-04-02 13:12:06 +02:00
if one != "foo" {
t.Fatalf("expected symone foo, got %v", one)
}
2023-04-02 13:12:06 +02:00
if two != "bar" {
t.Fatalf("expected symtwo bar, got %v", two)
}
}
2023-04-02 13:12:06 +02:00
func TestParseSymSig(t *testing.T) {
b := NewLine(nil, CATCH, []string{"baz"}, nil, []uint8{0x0d})
sym, n, b, err := ParseCatch(b)
2023-03-31 20:24:30 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
}
2023-04-02 13:12:06 +02:00
if sym != "baz" {
t.Fatalf("expected sym baz, got %v", sym)
}
2023-04-02 13:12:06 +02:00
if n != 13 {
t.Fatalf("expected n 13, got %v", n)
}
}
2023-03-31 20:24:30 +02:00
2023-04-02 13:12:06 +02:00
func TestParseSymAndLen(t *testing.T) {
b := NewLine(nil, LOAD, []string{"foo"}, []byte{0x2a}, nil)
sym, n, b, err := ParseLoad(b)
2023-03-31 20:24:30 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-03-31 20:24:30 +02:00
}
2023-04-02 13:12:06 +02:00
if sym != "foo" {
t.Fatalf("expected sym foo, got %v", sym)
2023-03-31 20:24:30 +02:00
}
2023-04-02 13:12:06 +02:00
if n != 42 {
t.Fatalf("expected n 42, got %v", n)
2023-03-31 20:24:30 +02:00
}
2023-04-02 13:12:06 +02:00
b = NewLine(nil, LOAD, []string{"bar"}, []byte{0x02, 0x9a}, nil)
sym, n, b, err = ParseLoad(b)
2023-04-01 22:25:20 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-04-01 22:25:20 +02:00
}
2023-04-02 13:12:06 +02:00
if sym != "bar" {
t.Fatalf("expected sym foo, got %v", sym)
}
if n != 666 {
t.Fatalf("expected n 666, got %v", n)
2023-04-01 22:25:20 +02:00
}
2023-04-02 13:12:06 +02:00
b = NewLine(nil, LOAD, []string{"baz"}, []byte{0x0}, nil)
sym, n, b, err = ParseLoad(b)
2023-04-01 22:25:20 +02:00
if err != nil {
2023-04-02 13:12:06 +02:00
t.Fatal(err)
2023-04-01 22:25:20 +02:00
}
2023-04-02 13:12:06 +02:00
if sym != "baz" {
t.Fatalf("expected sym foo, got %v", sym)
2023-04-01 22:25:20 +02:00
}
2023-04-02 13:12:06 +02:00
if n != 0 {
t.Fatalf("expected n 666, got %v", n)
2023-04-01 22:25:20 +02:00
}
}