menu_test.go (863B)
1 package asm 2 3 import ( 4 "testing" 5 6 "git.defalsify.org/vise.git/vm" 7 ) 8 9 10 func TestMenuInterpreter(t *testing.T) { 11 m := NewMenuProcessor() 12 err := m.Add("DOWN", "0", "inky", "foo") 13 if err != nil { 14 t.Fatal(err) 15 } 16 err = m.Add("NEXT", "1", "pinky", "") 17 if err != nil { 18 t.Fatal(err) 19 } 20 err = m.Add("PREVIOUS", "2", "blinkyclyde", "") 21 if err != nil { 22 t.Fatal(err) 23 } 24 err = m.Add("UP", "99", "tinky_winky", "") 25 if err != nil { 26 t.Fatal(err) 27 } 28 err = m.Add("BOGUS", "42", "lala poo", "plugh") 29 if err == nil { 30 t.Errorf("expected error on invalid menu item 'BOGUS'") 31 } 32 b := m.ToLines() 33 r, err := vm.ToString(b) 34 if err != nil { 35 t.Fatal(err) 36 } 37 expect := `MOUT inky 0 38 MNEXT pinky 1 39 MPREV blinkyclyde 2 40 MOUT tinky_winky 99 41 HALT 42 INCMP foo 0 43 INCMP > 1 44 INCMP < 2 45 INCMP _ 99 46 ` 47 if r != expect { 48 t.Errorf("expected:\n\t%v\ngot:\n\t%v\n", expect, r) 49 } 50 }