go-vise

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

commit 9f9ef86b9eb5d6ef62f6d4e224a9e960f80a5cd1
parent 5a300944c85dc65ec798789550f9589abe78ef5d
Author: lash <dev@holbrook.no>
Date:   Fri, 31 Mar 2023 18:17:43 +0100

Add error to arg getset

Diffstat:
Mgo/state/state.go | 10+++++++---
Mgo/vm/vm_test.go | 14+++++++++++++-
2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/go/state/state.go b/go/state/state.go @@ -39,12 +39,16 @@ func(st State) WithCacheSize(cacheSize uint32) State { return st } -func(st *State) PutArg(input string) { +func(st *State) PutArg(input string) error { st.Arg = &input + return nil } -func(st *State) PopArg() string { - return *st.Arg +func(st *State) PopArg() (string, error) { + if st.Arg == nil { + return "", fmt.Errorf("arg is not set") + } + return *st.Arg, nil } func(st *State) Down(input string) { diff --git a/go/vm/vm_test.go b/go/vm/vm_test.go @@ -16,6 +16,7 @@ import ( var dynVal = "three" type TestResource struct { + state *state.State } func getOne(input []byte, ctx context.Context) (string, error) { @@ -30,6 +31,15 @@ func getDyn(input []byte, ctx context.Context) (string, error) { return dynVal, nil } +type TestStatefulResolver struct { + state *state.State +} + + +func (r *TestResource) getEachArg(input []byte, ctx context.Context) (string, error) { + return r.state.PopArg() +} + func (r *TestResource) Get(sym string) (string, error) { switch sym { case "foo": @@ -70,6 +80,8 @@ func (r *TestResource) FuncFor(sym string) (resource.EntryFunc, error) { return getTwo, nil case "dyn": return getDyn, nil + case "arg": + return r.getEachArg, nil } return nil, fmt.Errorf("invalid function: '%s'", sym) } @@ -92,7 +104,7 @@ func TestRun(t *testing.T) { _ = r } -func TestRunLoad(t *testing.T) { +func TestRunLoadRender(t *testing.T) { st := state.NewState(5) st.Down("barbarbar") rs := TestResource{}