diff --git a/go/engine/loop_test.go b/go/engine/loop_test.go index d105012..682c2ab 100644 --- a/go/engine/loop_test.go +++ b/go/engine/loop_test.go @@ -3,6 +3,7 @@ package engine import ( "bytes" "context" + "fmt" "log" "strings" "testing" @@ -12,11 +13,10 @@ import ( "git.defalsify.org/festive/state" ) -func TestLoopCorrect(t *testing.T) { +func TestLoopBackForth(t *testing.T) { generateTestData(t) ctx := context.TODO() st := state.NewState(0) - //rs := NewFsWrapper(dataDir, &st) rs := resource.NewFsResource(dataDir) ca := cache.NewCache().WithCacheSize(1024) @@ -42,3 +42,45 @@ func TestLoopCorrect(t *testing.T) { t.Fatal(err) } } + +func TestLoopBrowse(t *testing.T) { + generateTestData(t) + ctx := context.TODO() + st := state.NewState(0) + rs := resource.NewFsResource(dataDir) + ca := cache.NewCache().WithCacheSize(1024) + + cfg := Config{ + OutputSize: 68, + } + en := NewEngine(cfg, &st, &rs, ca) + err := en.Init("root", ctx) + if err != nil { + t.Fatal(err) + } + + input := []string{ + "1", + "2", + "00", + "11", + "00", + } + inputStr := strings.Join(input, "\n") + inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a)) + outputBuf := bytes.NewBuffer(nil) + log.Printf("running with input: %s", inputBuf.Bytes()) + + err = Loop(&en, "root", ctx, inputBuf, outputBuf) + if err != nil { + t.Fatal(err) + } + + location, idx := st.Where() + if location != "long" { + fmt.Errorf("expected location 'long', got %s", location) + } + if idx != 1 { + fmt.Errorf("expected idx 1, got %v", idx) + } +} diff --git a/go/render/page.go b/go/render/page.go index e5ef538..e7ce682 100644 --- a/go/render/page.go +++ b/go/render/page.go @@ -230,7 +230,8 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st netRemaining := remaining if len(sinkValues) > 1 { - netRemaining -= menuSizes[1] + log.Printf("menusizes %v", menuSizes) + netRemaining -= menuSizes[1] - 1 } for i, v := range sinkValues { @@ -253,6 +254,7 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st } if tb.Len() > 0 { tb.WriteByte(byte(0x00)) + l += 1 } tb.WriteString(v) }