commit c3d634c1d3abedf671c6dceddc55feab8e0638d6
parent 78261239b22d5b88f09cf5f74dff0e5661c2d633
Author: lash <dev@holbrook.no>
Date: Fri, 31 Mar 2023 19:40:54 +0100
Execute arg with render
Diffstat:
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/go/vm/vm.go b/go/vm/vm.go
@@ -37,9 +37,10 @@ func Apply(input []byte, instruction []byte, st state.State, rs resource.Fetcher
st.PutArg(arg)
}
if sym == "" {
- instruction = NewLine([]byte{}, MOVE, []string{"_catch"}, nil , nil)
+ instruction = NewLine([]byte{}, MOVE, []string{"_catch"}, nil, nil)
} else {
- instruction = NewLine(instruction, MOVE, []string{sym}, nil, nil)
+ new_instruction := NewLine([]byte{}, MOVE, []string{sym}, nil, nil)
+ instruction = append(new_instruction, instruction...)
}
st, instruction, err = Run(instruction, st, rs, ctx)
diff --git a/go/vm/vm_test.go b/go/vm/vm_test.go
@@ -246,6 +246,41 @@ func TestRunArgInvalid(t *testing.T) {
if r != "_catch" {
t.Errorf("expected where-state _catch, got %v", r)
}
-
}
+func TestRunArgInstructions(t *testing.T) {
+ st := state.NewState(5)
+ rt := router.NewRouter()
+ rt.Add("foo", "bar")
+ rs := TestResource{}
+ b := []byte{0x03}
+ b = append(b, []byte("foo")...)
+ b = append(b, rt.ToBytes()...)
+
+ bi := NewLine([]byte{}, LOAD, []string{"one"}, nil, []uint8{0})
+ bi = NewLine(bi, LOAD, []string{"two"}, nil, []uint8{0})
+ bi = NewLine(bi, MAP, []string{"one"}, nil, nil)
+ bi = NewLine(bi, MAP, []string{"two"}, nil, nil)
+ var err error
+ st, b, err = Apply(b, bi, st, &rs, context.TODO())
+ if err != nil {
+ t.Error(err)
+ }
+ l := len(b)
+ if l != 0 {
+ t.Errorf("expected empty remainder, got length %v: %v", l, b)
+ }
+ loc := st.Where()
+ if loc != "bar" {
+ t.Errorf("expected where-state _catch, got %v", loc)
+ }
+ m, err := st.Get()
+ if err != nil {
+ t.Error(err)
+ }
+ r, err := rs.Render(loc, m)
+ if err != nil {
+ t.Error(err)
+ }
+ _ = r
+}