vise/asm/menu_test.go

51 lines
869 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
2023-04-14 10:59:37 +02:00
"git.defalsify.org/vise/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"
MNEXT 1 "pinky"
MPREV 2 "blinky clyde"
2023-04-03 09:22:01 +02:00
MOUT 99 "tinky-winky"
HALT
INCMP 0 foo
INCMP 1 >
INCMP 2 <
2023-04-03 09:22:01 +02:00
INCMP 99 _
`
if r != expect {
t.Errorf("expected:\n\t%v\ngot:\n\t%v\n", expect, r)
}
}