From c3d634c1d3abedf671c6dceddc55feab8e0638d6 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 31 Mar 2023 19:40:54 +0100 Subject: [PATCH] Execute arg with render --- go/vm/vm.go | 5 +++-- go/vm/vm_test.go | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/go/vm/vm.go b/go/vm/vm.go index d61c925..19b1779 100644 --- 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 index 4de5253..7f5afa3 100644 --- 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 +}