Execute arg with render

This commit is contained in:
lash 2023-03-31 19:40:54 +01:00
parent 78261239b2
commit c3d634c1d3
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 39 additions and 3 deletions

View File

@ -39,7 +39,8 @@ func Apply(input []byte, instruction []byte, st state.State, rs resource.Fetcher
if sym == "" { if sym == "" {
instruction = NewLine([]byte{}, MOVE, []string{"_catch"}, nil, nil) instruction = NewLine([]byte{}, MOVE, []string{"_catch"}, nil, nil)
} else { } 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) st, instruction, err = Run(instruction, st, rs, ctx)

View File

@ -246,6 +246,41 @@ func TestRunArgInvalid(t *testing.T) {
if r != "_catch" { if r != "_catch" {
t.Errorf("expected where-state _catch, got %v", r) 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
}