go-vise

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

commit 238f4546ffa07217a369a258b228d47bfb9b7b23
parent 2b34149aa9e9c91bdf46d66dc3c0f118b292d74f
Author: lash <dev@holbrook.no>
Date:   Sat,  8 Apr 2023 15:27:52 +0100

Move test fixture code for resource wrapper to separate file

Diffstat:
Mgo/resource/resource_test.go | 49+++++++++++++++++++++++++++++++++++++++++++++++--
Mgo/resource/size_test.go | 49-------------------------------------------------
2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/go/resource/resource_test.go b/go/resource/resource_test.go @@ -1,9 +1,54 @@ package resource import ( - "testing" + "context" + "fmt" ) -func TestRenderLimit(t *testing.T) { +type TestSizeResource struct { + *MenuResource +} + +func getTemplate(sym string, sizer *Sizer) (string, error) { + var tpl string + switch sym { + case "small": + tpl = "one {{.foo}} two {{.bar}} three {{.baz}}" + case "toobig": + tpl = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus in mattis lorem. Aliquam erat volutpat. Ut vitae metus." + case "pages": + tpl = "one {{.foo}} two {{.bar}} three {{.baz}}\n{{.xyzzy}}" + } + return tpl, nil +} + +func funcFor(sym string) (EntryFunc, error) { + switch sym { + case "foo": + return getFoo, nil + case "bar": + return getBar, nil + case "baz": + return getBaz, nil + case "xyzzy": + return getXyzzy, nil + } + return nil, fmt.Errorf("unknown func: %s", sym) +} + +func getFoo(ctx context.Context) (string, error) { + return "inky", nil +} + +func getBar(ctx context.Context) (string, error) { + return "pinky", nil +} + +func getBaz(ctx context.Context) (string, error) { + return "blinky", nil +} + +func getXyzzy(ctx context.Context) (string, error) { + return "inky pinky\nblinky clyde sue\ntinkywinky dipsy\nlala poo\none two three four five six seven\neight nine ten\neleven twelve", nil } diff --git a/go/resource/size_test.go b/go/resource/size_test.go @@ -1,60 +1,11 @@ package resource import ( - "fmt" - "context" "testing" "git.defalsify.org/festive/state" ) -type TestSizeResource struct { - *MenuResource -} - -func getTemplate(sym string, sizer *Sizer) (string, error) { - var tpl string - switch sym { - case "small": - tpl = "one {{.foo}} two {{.bar}} three {{.baz}}" - case "toobig": - tpl = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus in mattis lorem. Aliquam erat volutpat. Ut vitae metus." - case "pages": - tpl = "one {{.foo}} two {{.bar}} three {{.baz}}\n{{.xyzzy}}" - } - return tpl, nil -} - -func funcFor(sym string) (EntryFunc, error) { - switch sym { - case "foo": - return getFoo, nil - case "bar": - return getBar, nil - case "baz": - return getBaz, nil - case "xyzzy": - return getXyzzy, nil - } - return nil, fmt.Errorf("unknown func: %s", sym) -} - -func getFoo(ctx context.Context) (string, error) { - return "inky", nil -} - -func getBar(ctx context.Context) (string, error) { - return "pinky", nil -} - -func getBaz(ctx context.Context) (string, error) { - return "blinky", nil -} - -func getXyzzy(ctx context.Context) (string, error) { - return "inky pinky\nblinky clyde sue\ntinkywinky dipsy\nlala poo\none two three four five six seven\neight nine ten\neleven twelve", nil -} - func TestSizeLimit(t *testing.T) { st := state.NewState(0).WithOutputSize(128) mrs := NewMenuResource().WithEntryFuncGetter(funcFor).WithTemplateGetter(getTemplate)