go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 782b020b8dc9d18fe8890b9202afd014cccc9761
parent 503e6d0eabf40c53b27c24281ee933fa3fb99074
Author: lash <dev@holbrook.no>
Date:   Wed, 26 Apr 2023 08:52:18 +0100

WIP implement language for menu

Diffstat:
Masm/asm_test.go | 10+++++-----
Masm/menu_test.go | 12++++++------
Mengine/default.go | 12++++++------
Mengine/engine.go | 7+++++--
Mengine/engine_test.go | 44++++++++++++++++++++++++++++++++++++++++++--
Mengine/loop_test.go | 6+++---
Mexamples/profile/main.go | 2+-
Mexamples/validate/main.go | 2+-
Mrender/menu.go | 34+++++++++++++++++++++++++++++-----
Mrender/menu_test.go | 16++++++++++------
Mrender/page.go | 8++++----
Mresource/fs.go | 38++++++++++++++++++++++++++++++++++++--
Mresource/fs_test.go | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mresource/mem.go | 11+++++++++++
Mresource/resource.go | 14++++++++++++++
Mtestdata/foo.vis | 6++----
Mtestdata/testdata.go | 9++++++++-
Mvm/debug.go | 9++++++---
Mvm/debug_test.go | 9++++++---
19 files changed, 254 insertions(+), 54 deletions(-)

diff --git a/asm/asm_test.go b/asm/asm_test.go @@ -52,7 +52,7 @@ func TestParserSized(t *testing.T) { func TestParseDisplay(t *testing.T) { var b []byte - b = vm.NewLine(b, vm.MOUT, []string{"foo", "baz ba zbaz"}, nil, nil) + b = vm.NewLine(b, vm.MOUT, []string{"foo", "baz_ba_zbaz"}, nil, nil) s, err := vm.ToString(b) log.Printf("parsing:\n%s\n", s) @@ -65,9 +65,9 @@ func TestParseDisplay(t *testing.T) { t.Fatalf("expected 18 byte write count, got %v", n) } rb := r.Bytes() - expect := []byte{0x00, vm.MOUT, 0x03, 0x66, 0x6f, 0x6f, 0x0b, 0x62, 0x61, 0x7a, 0x20, 0x62, 0x61, 0x20, 0x7a, 0x62, 0x61, 0x7a} + expect := []byte{0x00, vm.MOUT, 0x03, 0x66, 0x6f, 0x6f, 0x0b, 0x62, 0x61, 0x7a, 0x5f, 0x62, 0x61, 0x5f, 0x7a, 0x62, 0x61, 0x7a} if !bytes.Equal(rb, expect) { - t.Fatalf("expected %x, got %x", expect, rb) + t.Fatalf("expected:\n\t%x\ngot:\n\t%x", expect, rb) } } @@ -216,7 +216,7 @@ func TestParserWriteMultiple(t *testing.T) { b = vm.NewLine(b, vm.CATCH, []string{"xyzzy"}, []byte{0x02, 0x9a}, []uint8{1}) b = vm.NewLine(b, vm.INCMP, []string{"pinky", "inky"}, nil, nil) b = vm.NewLine(b, vm.LOAD, []string{"foo"}, []byte{42}, nil) - b = vm.NewLine(b, vm.MOUT, []string{"bar", "bar barb az"}, nil, nil) + b = vm.NewLine(b, vm.MOUT, []string{"bar", "bar_barb_az"}, nil, nil) s, err := vm.ToString(b) log.Printf("parsing:\n%s\n", s) @@ -227,7 +227,7 @@ func TestParserWriteMultiple(t *testing.T) { } log.Printf("result %x", r.Bytes()) - r_expect_hex := "000700010578797a7a7902029a01000804696e6b790570696e6b79000303666f6f012a000a036261720b626172206261726220617a" + r_expect_hex := "000700010578797a7a7902029a01000804696e6b790570696e6b79000303666f6f012a000a0b6261725f626172625f617a03626172" r_expect, err := hex.DecodeString(r_expect_hex) if err != nil { t.Fatal(err) diff --git a/asm/menu_test.go b/asm/menu_test.go @@ -17,11 +17,11 @@ func TestMenuInterpreter(t *testing.T) { if err != nil { t.Fatal(err) } - err = m.Add("PREVIOUS", "2", "blinky clyde", "") + err = m.Add("PREVIOUS", "2", "blinkyclyde", "") if err != nil { t.Fatal(err) } - err = m.Add("UP", "99", "tinky-winky", "") + err = m.Add("UP", "99", "tinky_winky", "") if err != nil { t.Fatal(err) } @@ -34,10 +34,10 @@ func TestMenuInterpreter(t *testing.T) { if err != nil { t.Fatal(err) } - expect := `MOUT 0 "inky" -MNEXT 1 "pinky" -MPREV 2 "blinky clyde" -MOUT 99 "tinky-winky" + expect := `MOUT 0 inky +MNEXT 1 pinky +MPREV 2 blinkyclyde +MOUT 99 tinky_winky HALT INCMP 0 foo INCMP 1 > diff --git a/engine/default.go b/engine/default.go @@ -35,7 +35,7 @@ func NewDefaultEngine(dir string, persisted bool, session *string) (EngineIsh, e return nil, err } pr := persist.NewFsPersister(dp) - en, err = NewPersistedEngine(ctx, cfg, pr, &rs) + en, err = NewPersistedEngine(ctx, cfg, pr, rs) if err != nil { Logg.Infof("persisted engine create error. trying again with persisting empty state first...") pr = pr.WithContent(&st, ca) @@ -43,10 +43,10 @@ func NewDefaultEngine(dir string, persisted bool, session *string) (EngineIsh, e if err != nil { return nil, err } - en, err = NewPersistedEngine(ctx, cfg, pr, &rs) + en, err = NewPersistedEngine(ctx, cfg, pr, rs) } } else { - enb := NewEngine(ctx, cfg, &st, &rs, ca) + enb := NewEngine(ctx, cfg, &st, rs, ca) en = &enb } return en, err @@ -76,7 +76,7 @@ func NewSizedEngine(dir string, size uint32, persisted bool, session *string) (E return nil, err } pr := persist.NewFsPersister(dp) - en, err = NewPersistedEngine(ctx, cfg, pr, &rs) + en, err = NewPersistedEngine(ctx, cfg, pr, rs) if err != nil { Logg.Infof("persisted engine create error. trying again with persisting empty state first...") pr = pr.WithContent(&st, ca) @@ -84,10 +84,10 @@ func NewSizedEngine(dir string, size uint32, persisted bool, session *string) (E if err != nil { return nil, err } - en, err = NewPersistedEngine(ctx, cfg, pr, &rs) + en, err = NewPersistedEngine(ctx, cfg, pr, rs) } } else { - enb := NewEngine(ctx, cfg, &st, &rs, ca) + enb := NewEngine(ctx, cfg, &st, rs, ca) en = &enb } return en, err diff --git a/engine/engine.go b/engine/engine.go @@ -58,10 +58,13 @@ func NewEngine(ctx context.Context, cfg Config, st *state.State, rs resource.Res engine.session = cfg.SessionId var err error - if st.Language != nil { + if st.Language == nil { if cfg.Language != "" { err = st.SetLanguage(cfg.Language) - panic(err) + if err != nil { + panic(err) + } + Logg.InfoCtxf(ctx, "set language from config", "language", cfg.Language) } } diff --git a/engine/engine_test.go b/engine/engine_test.go @@ -29,7 +29,7 @@ type FsWrapper struct { func NewFsWrapper(path string, st *state.State) FsWrapper { rs := resource.NewFsResource(path) wr := FsWrapper { - &rs, + rs, st, } wr.AddLocalFunc("one", wr.one) @@ -288,7 +288,6 @@ func TestLanguageRender(t *testing.T) { t.Fatal(err) } - b := vm.NewLine(nil, vm.LOAD, []string{"set_lang"}, []byte{0x01, 0x00}, nil) b = vm.NewLine(b, vm.MOVE, []string{"lang"}, nil, nil) st.SetCode(b) @@ -310,3 +309,44 @@ func TestLanguageRender(t *testing.T) { } } + +func TestConfigLanguageRender(t *testing.T) { + generateTestData(t) + ctx := context.TODO() + st := state.NewState(0) + rs := NewFsWrapper(dataDir, &st) + ca := cache.NewCache() + + cfg := Config{ + Root: "root", + Language: "nor", + } + en := NewEngine(ctx, cfg, &st, &rs, ca) + + var err error + _, err = en.Init(ctx) + if err != nil { + t.Fatal(err) + } + + b := vm.NewLine(nil, vm.LOAD, []string{"set_lang"}, []byte{0x01, 0x00}, nil) + b = vm.NewLine(b, vm.MOVE, []string{"lang"}, nil, nil) + st.SetCode(b) + + _, err = en.Exec(ctx, []byte("foo")) + if err != nil { + t.Fatal(err) + } + br := bytes.NewBuffer(nil) + _, err = en.WriteResult(ctx, br) + if err != nil { + t.Fatal(err) + } + + expect := `dette endrer med språket one +0:tilbake` + r := br.String() + if r != expect { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s", expect, r) + } +} diff --git a/engine/loop_test.go b/engine/loop_test.go @@ -23,7 +23,7 @@ func TestLoopTop(t *testing.T) { cfg := Config{ Root: "root", } - en := NewEngine(ctx, cfg, &st, &rs, ca) + en := NewEngine(ctx, cfg, &st, rs, ca) var err error _, err = en.Init(ctx) if err != nil { @@ -60,7 +60,7 @@ func TestLoopBackForth(t *testing.T) { cfg := Config{ Root: "root", } - en := NewEngine(ctx, cfg, &st, &rs, ca) + en := NewEngine(ctx, cfg, &st, rs, ca) var err error _, err = en.Init(ctx) if err != nil { @@ -95,7 +95,7 @@ func TestLoopBrowse(t *testing.T) { OutputSize: 68, Root: "root", } - en := NewEngine(ctx, cfg, &st, &rs, ca) + en := NewEngine(ctx, cfg, &st, rs, ca) var err error _, err = en.Init(ctx) if err != nil { diff --git a/examples/profile/main.go b/examples/profile/main.go @@ -98,7 +98,7 @@ func main() { st := state.NewState(3) rsf := resource.NewFsResource(scriptDir) - rs, ok := newProfileResource(&st, &rsf).(*profileResource) + rs, ok := newProfileResource(&st, rsf).(*profileResource) if !ok { os.Exit(1) } diff --git a/examples/validate/main.go b/examples/validate/main.go @@ -57,7 +57,7 @@ func main() { st := state.NewState(1) rsf := resource.NewFsResource(scriptDir) - rs := verifyResource{&rsf, &st} + rs := verifyResource{rsf, &st} rs.AddLocalFunc("verifyinput", rs.verify) rs.AddLocalFunc("again", rs.again) ca := cache.NewCache() diff --git a/render/menu.go b/render/menu.go @@ -1,7 +1,10 @@ package render import ( + "context" "fmt" + + "git.defalsify.org/vise.git/resource" ) // BrowseError is raised when browsing outside the page range of a rendered node. @@ -39,6 +42,7 @@ func DefaultBrowseConfig() BrowseConfig { // Menu renders menus. May be included in a Page object to render menus for pages. type Menu struct { + rs resource.Resource menu [][2]string // selector and title for menu items. browse BrowseConfig // browse definitions. pageCount uint16 // number of pages the menu should represent. @@ -79,6 +83,11 @@ func(m *Menu) WithDispose() *Menu { return m } +func(m *Menu) WithResource(rs resource.Resource) *Menu { + m.rs = rs + return m +} + func(m Menu) IsSink() bool { return m.sink } @@ -117,22 +126,22 @@ func(m *Menu) Put(selector string, title string) error { //} // mainSize, prevsize, nextsize, nextsize+prevsize -func(m *Menu) Sizes() ([4]uint32, error) { +func(m *Menu) Sizes(ctx context.Context) ([4]uint32, error) { var menuSizes [4]uint32 cfg := m.GetBrowseConfig() tmpm := NewMenu().WithBrowseConfig(cfg) - v, err := tmpm.Render(0) + v, err := tmpm.Render(ctx, 0) if err != nil { return menuSizes, err } menuSizes[0] = uint32(len(v)) tmpm = tmpm.WithPageCount(2) - v, err = tmpm.Render(0) + v, err = tmpm.Render(ctx, 0) if err != nil { return menuSizes, err } menuSizes[1] = uint32(len(v)) - menuSizes[0] - v, err = tmpm.Render(1) + v, err = tmpm.Render(ctx, 1) if err != nil { return menuSizes, err } @@ -141,10 +150,21 @@ func(m *Menu) Sizes() ([4]uint32, error) { return menuSizes, nil } +func(m *Menu) titleFor(ctx context.Context, title string) (string, error) { + if m.rs == nil { + return title, nil + } + r, err := m.rs.GetMenu(ctx, title) + if err != nil { + return title, err + } + return r, nil +} + // Render returns the full current state of the menu as a string. // // After this has been executed, the state of the menu will be empty. -func(m *Menu) Render(idx uint16) (string, error) { +func(m *Menu) Render(ctx context.Context, idx uint16) (string, error) { var menuCopy [][2]string if m.keep { for _, v := range m.menu { @@ -167,6 +187,10 @@ func(m *Menu) Render(idx uint16) (string, error) { if l > 0 { r += "\n" } + title, err = m.titleFor(ctx, title) + if err != nil { + return "", err + } r += fmt.Sprintf("%s:%s", choice, title) } if m.keep { diff --git a/render/menu_test.go b/render/menu_test.go @@ -1,6 +1,7 @@ package render import ( + "context" "testing" ) @@ -14,7 +15,9 @@ func TestMenuInit(t *testing.T) { if err != nil { t.Fatal(err) } - r, err := m.Render(0) + + ctx := context.TODO() + r, err := m.Render(ctx, 0) if err != nil { t.Fatal(err) } @@ -24,7 +27,7 @@ func TestMenuInit(t *testing.T) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect, r) } - r, err = m.Render(1) + r, err = m.Render(ctx, 1) if err == nil { t.Fatalf("expected render fail") } @@ -43,7 +46,8 @@ func TestMenuBrowse(t *testing.T) { t.Fatal(err) } - r, err := m.Render(0) + ctx := context.TODO() + r, err := m.Render(ctx, 0) if err != nil { t.Fatal(err) } @@ -54,7 +58,7 @@ func TestMenuBrowse(t *testing.T) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect, r) } - r, err = m.Render(1) + r, err = m.Render(ctx, 1) if err != nil { t.Fatal(err) } @@ -66,7 +70,7 @@ func TestMenuBrowse(t *testing.T) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect, r) } - r, err = m.Render(2) + r, err = m.Render(ctx, 2) if err != nil { t.Fatal(err) } @@ -77,7 +81,7 @@ func TestMenuBrowse(t *testing.T) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect, r) } - _, err = m.Render(3) + _, err = m.Render(ctx, 3) if err == nil { t.Fatalf("expected render fail") } diff --git a/render/page.go b/render/page.go @@ -34,7 +34,7 @@ func NewPage(cache cache.Memory, rs resource.Resource) *Page { // WithMenu sets a menu renderer for the page. func(pg *Page) WithMenu(menu *Menu) *Page { - pg.menu = menu + pg.menu = menu.WithResource(pg.resource) //if pg.sizer != nil { // pg.sizer = pg.sizer.WithMenuSize(pg.menu.ReservedSize()) //} @@ -292,7 +292,7 @@ func(pg *Page) joinSink(sinkValues []string, remaining uint32, menuSizes [4]uint } func(pg *Page) applyMenuSink(ctx context.Context) ([]string, error) { - s, err := pg.menu.WithDispose().WithPages().Render(0) + s, err := pg.menu.WithDispose().WithPages().Render(ctx, 0) if err != nil { return nil, err } @@ -346,7 +346,7 @@ func(pg *Page) prepare(ctx context.Context, sym string, values map[string]string // pre-calculate the menu sizes for all browse conditions var menuSizes [4]uint32 if pg.menu != nil { - menuSizes, err = pg.menu.Sizes() + menuSizes, err = pg.menu.Sizes(ctx) if err != nil { return nil, err } @@ -385,7 +385,7 @@ func(pg *Page) render(ctx context.Context, sym string, values map[string]string, r += s if pg.menu != nil { - s, err = pg.menu.Render(idx) + s, err = pg.menu.Render(ctx, idx) if err != nil { return "", err } diff --git a/resource/fs.go b/resource/fs.go @@ -17,18 +17,24 @@ type FsResource struct { MenuResource Path string fns map[string]EntryFunc +// languageStrict bool } -func NewFsResource(path string) FsResource { +func NewFsResource(path string) *FsResource { absPath, err := filepath.Abs(path) if err != nil { panic(err) } - return FsResource{ + return &FsResource{ Path: absPath, } } +//func(fsr *FsResource) WithStrictLanguage() *FsResource { +// fsr.languageStrict = true +// return fsr +//} + func(fsr FsResource) GetTemplate(ctx context.Context, sym string) (string, error) { fp := path.Join(fsr.Path, sym) fpl := fp @@ -60,6 +66,34 @@ func(fsr FsResource) GetCode(sym string) ([]byte, error) { return ioutil.ReadFile(fp) } +func(fsr FsResource) GetMenu(ctx context.Context, sym string) (string, error) { + fp := path.Join(fsr.Path, sym + "_menu") + fpl := fp + v := ctx.Value("Language") + if v != nil { + lang := v.(lang.Language) + fpl += "_" + lang.Code + } + var r []byte + var err error + r, err = ioutil.ReadFile(fpl) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + if fpl != fp { + r, err = ioutil.ReadFile(fp) + } + } + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return sym, nil + } + return "", fmt.Errorf("failed getting template for sym '%s': %v", sym, err) + } + } + s := string(r) + return strings.TrimSpace(s), err +} + func(fsr *FsResource) AddLocalFunc(sym string, fn EntryFunc) { if fsr.fns == nil { fsr.fns = make(map[string]EntryFunc) diff --git a/resource/fs_test.go b/resource/fs_test.go @@ -65,3 +65,62 @@ func TestResourceLanguage(t *testing.T) { t.Fatalf("expected '%s', got '%s'", tmpl, r) } } + +func TestResourceMenuLanguage(t *testing.T) { + lang, err := lang.LanguageFromCode("nor") + if err != nil { + t.Fatal(err) + } + ctx := context.TODO() + + dir, err := os.MkdirTemp("", "vise_fsresource") + if err != nil { + t.Fatal(err) + } + rs := NewFsResource(dir) + + r, err := rs.GetMenu(ctx, "foo") + if err != nil { + t.Fatal(err) + } + if r != "foo" { + t.Fatalf("expected 'foo', got '%s'", r) + } + + fp := path.Join(dir, "foo_menu") + menu := "foo bar" + err = os.WriteFile(fp, []byte(menu), 0600) + if err != nil { + t.Fatal(err) + } + r, err = rs.GetMenu(ctx, "foo") + if err != nil { + t.Fatal(err) + } + if r != menu { + t.Fatalf("expected '%s', got '%s'", menu, r) + } + + ctx = context.WithValue(ctx, "Language", lang) + r, err = rs.GetMenu(ctx, "foo") + if err != nil { + t.Fatal(err) + } + if r != menu { + t.Fatalf("expected '%s', got '%s'", menu, r) + } + + fp = path.Join(dir, "foo_menu_nor") + menu = "baz bar" + err = os.WriteFile(fp, []byte(menu), 0600) + if err != nil { + t.Fatal(err) + } + r, err = rs.GetMenu(ctx, "foo") + if err != nil { + t.Fatal(err) + } + if r != menu { + t.Fatalf("expected '%s', got '%s'", menu, r) + } +} diff --git a/resource/mem.go b/resource/mem.go @@ -9,6 +9,7 @@ type MemResource struct { MenuResource templates map[string]string bytecodes map[string][]byte + menus map[string]string funcs map[string]EntryFunc } @@ -21,6 +22,7 @@ func NewMemResource() MemResource { mr.WithCodeGetter(mr.getCode) mr.WithTemplateGetter(mr.getTemplate) mr.WithEntryFuncGetter(mr.getFunc) + mr.WithMenuGetter(mr.getMenu) return mr } @@ -40,6 +42,15 @@ func(mr MemResource) getCode(sym string) ([]byte, error) { return r, nil } +func(mr MemResource) getMenu(ctx context.Context, sym string) (string, error) { + r, ok := mr.menus[sym] + if !ok { + r = sym + } + return r, nil + +} + func(mr MemResource) getFunc(sym string) (EntryFunc, error) { r, ok := mr.funcs[sym] if !ok { diff --git a/resource/resource.go b/resource/resource.go @@ -15,6 +15,7 @@ type Result struct { // EntryFunc is a function signature for retrieving value for a key type EntryFunc func(ctx context.Context, sym string, input []byte) (Result, error) type CodeFunc func(sym string) ([]byte, error) +type MenuFunc func(ctx context.Context, sym string) (string, error) type TemplateFunc func(ctx context.Context, sym string) (string, error) type FuncForFunc func(sym string) (EntryFunc, error) @@ -22,6 +23,7 @@ type FuncForFunc func(sym string) (EntryFunc, error) type Resource interface { GetTemplate(ctx context.Context, sym string) (string, error) // Get the template for a given symbol. GetCode(sym string) ([]byte, error) // Get the bytecode for the given symbol. + GetMenu(ctx context.Context, sym string) (string, error) // Receive menu test for menu symbol. FuncFor(sym string) (EntryFunc, error) // Resolve symbol content point for. } @@ -32,6 +34,7 @@ type MenuResource struct { sinkValues []string codeFunc CodeFunc templateFunc TemplateFunc + menuFunc MenuFunc funcFunc FuncForFunc } @@ -58,6 +61,12 @@ func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResou return m } +// WithMenuGetter sets the menu symbol resolver method. +func(m *MenuResource) WithMenuGetter(menuGetter MenuFunc) *MenuResource { + m.menuFunc = menuGetter + return m +} + // FuncFor implements Resource interface func(m MenuResource) FuncFor(sym string) (EntryFunc, error) { return m.funcFunc(sym) @@ -72,3 +81,8 @@ func(m MenuResource) GetCode(sym string) ([]byte, error) { func(m MenuResource) GetTemplate(ctx context.Context, sym string) (string, error) { return m.templateFunc(ctx, sym) } + +// GetCode implements Resource interface +func(m MenuResource) GetMenu(ctx context.Context, sym string) (string, error) { + return m.menuFunc(ctx, sym) +} diff --git a/testdata/foo.vis b/testdata/foo.vis @@ -1,9 +1,7 @@ -MOUT 1 "to foo" -MOUT 2 "go bar" +MOUT 1 tofoo +MOUT 2 gobar LOAD inky 20 HALT INCMP 1 _ INCMP 2 baz CATCH _catch 1 1 -DOWN foofoo 1 "go to foo" -UP 2 "up go go go" diff --git a/testdata/testdata.go b/testdata/testdata.go @@ -166,7 +166,14 @@ func lang() error { tpl = "dette endrer med språket {{.inky}}" fp := path.Join(DataDir, "lang_nor") - return os.WriteFile(fp, []byte(tpl), 0600) + err = os.WriteFile(fp, []byte(tpl), 0600) + if err != nil { + return err + } + + menu := "tilbake" + fp = path.Join(DataDir, "back_menu_nor") + return os.WriteFile(fp, []byte(menu), 0600) } func generate() error { diff --git a/vm/debug.go b/vm/debug.go @@ -120,7 +120,8 @@ func ParseAll(b []byte, w io.Writer) (int, error) { b = bb if err == nil { if w != nil { - rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + //rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + rs = fmt.Sprintf("%s %s %s\n", s, r, v) } } case MNEXT: @@ -128,7 +129,8 @@ func ParseAll(b []byte, w io.Writer) (int, error) { b = bb if err == nil { if w != nil { - rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + //rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + rs = fmt.Sprintf("%s %s %s\n", s, r, v) } } case MPREV: @@ -136,7 +138,8 @@ func ParseAll(b []byte, w io.Writer) (int, error) { b = bb if err == nil { if w != nil { - rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + //rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) + rs = fmt.Sprintf("%s %s %s\n", s, r, v) } } } diff --git a/vm/debug_test.go b/vm/debug_test.go @@ -96,7 +96,8 @@ func TestToString(t *testing.T) { if err != nil { t.Fatal(err) } - expect = "MNEXT 11 \"nextmenu\"\n" + //expect = "MNEXT 11 \"nextmenu\"\n" + expect = "MNEXT 11 nextmenu\n" if r != expect { t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) } @@ -106,7 +107,8 @@ func TestToString(t *testing.T) { if err != nil { t.Fatal(err) } - expect = "MPREV 222 \"previous menu item\"\n" + //expect = "MPREV 222 \"previous menu item\"\n" + expect = "MPREV 222 previous menu item\n" if r != expect { t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) } @@ -116,7 +118,8 @@ func TestToString(t *testing.T) { if err != nil { t.Fatal(err) } - expect = "MOUT 1 \"foo\"\n" + //expect = "MOUT 1 \"foo\"\n" + expect = "MOUT 1 foo\n" if r != expect { t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) }