Make assembler handle non-DOWN menu choices

This commit is contained in:
lash 2023-04-06 08:49:16 +01:00
parent d6a0314132
commit c748daa8f7
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 17 additions and 6 deletions

View File

@ -328,13 +328,20 @@ func(bt *Batcher) MenuExit(w io.Writer) (int, error) {
func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
bt.inMenu = true
var selector string
var sym string
if arg.Size != nil {
selector = strconv.FormatUint(uint64(*arg.Size), 10)
} else if arg.Selector != nil {
selector = *arg.Selector
}
log.Printf("menu processor add %v '%v' '%v' '%v'", code, *arg.Sym, selector, *arg.Desc)
err := bt.menuProcessor.Add(code, *arg.Sym, selector, *arg.Desc)
if selector == "" {
selector = *arg.Sym
} else if arg.Sym != nil {
sym = *arg.Sym
}
log.Printf("menu processor add %v '%v' '%v' '%v'", code, selector, *arg.Desc, sym)
err := bt.menuProcessor.Add(code, selector, *arg.Desc, sym)
return 0, err
}

View File

@ -94,7 +94,7 @@ func TestParseDouble(t *testing.T) {
func TestParseMenu(t *testing.T) {
s := `DOWN foobar 00 "inky pinky"
UP bazbar s1 "tinkywinky"
UP s1 "tinkywinky"
`
r := bytes.NewBuffer(nil)
n, err := Parse(s, r)

View File

@ -48,6 +48,9 @@ func(mp *MenuProcessor) Add(bop string, choice string, display string, target st
if bopCode == 0 {
return fmt.Errorf("unknown menu instruction: %v", bop)
}
if len(target) > 0 && bopCode != MENU_DOWN {
return fmt.Errorf("target is only valid for DOWN")
}
m := menuItem{
code: bopCode,
choice: choice,

View File

@ -13,15 +13,15 @@ func TestMenuInterpreter(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = m.Add("NEXT", "1", "pinky", "bar")
err = m.Add("NEXT", "1", "pinky", "")
if err != nil {
t.Fatal(err)
}
err = m.Add("PREVIOUS", "2", "blinky clyde", "baz")
err = m.Add("PREVIOUS", "2", "blinky clyde", "")
if err != nil {
t.Fatal(err)
}
err = m.Add("UP", "99", "tinky-winky", "xyzzy")
err = m.Add("UP", "99", "tinky-winky", "")
if err != nil {
t.Fatal(err)
}

1
go/testdata/foo.fst vendored
View File

@ -6,3 +6,4 @@ INCMP 1 _
INCMP 2 baz
CATCH _catch 1 1
DOWN foofoo 1 "go to foo"
UP 2 "up go go go"