vise/go/asm/menu_test.go

49 lines
850 B
Go
Raw Normal View History

2023-04-04 11:32:39 +02:00
package asm
2023-04-03 09:22:01 +02:00
import (
"testing"
2023-04-04 11:32:39 +02:00
"git.defalsify.org/festive/vm"
2023-04-03 09:22:01 +02:00
)
func TestMenuInterpreter(t *testing.T) {
m := NewMenuProcessor()
err := m.Add("DOWN", "0", "inky", "foo")
if err != nil {
t.Fatal(err)
}
err = m.Add("NEXT", "1", "pinky", "")
2023-04-03 09:22:01 +02:00
if err != nil {
t.Fatal(err)
}
err = m.Add("PREVIOUS", "2", "blinky clyde", "")
2023-04-03 09:22:01 +02:00
if err != nil {
t.Fatal(err)
}
err = m.Add("UP", "99", "tinky-winky", "")
2023-04-03 09:22:01 +02:00
if err != nil {
t.Fatal(err)
}
err = m.Add("BOGUS", "42", "lala poo", "plugh")
if err == nil {
t.Errorf("expected error on invalid menu item 'BOGUS'")
}
b := m.ToLines()
2023-04-04 11:32:39 +02:00
r, err := vm.ToString(b)
2023-04-03 09:22:01 +02:00
if err != nil {
t.Fatal(err)
}
expect := `MOUT 0 "inky"
MOUT 1 "pinky"
MOUT 2 "blinky clyde"
MOUT 99 "tinky-winky"
HALT
INCMP 0 foo
INCMP 99 _
`
if r != expect {
t.Errorf("expected:\n\t%v\ngot:\n\t%v\n", expect, r)
}
}