go-vise

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

commit 550a674b0f4d674905d251847ec3c03e725ab9cc
parent 26659e080a9ef296f1d9651d570c0aad263a6086
Author: lash <dev@holbrook.no>
Date:   Thu, 12 Sep 2024 00:01:36 +0100

Hit applyTarget cases and reach >80% coverage vm/input.go

Diffstat:
Mvm/input_test.go | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/vm/input_test.go b/vm/input_test.go @@ -1,9 +1,11 @@ package vm import ( + "context" "testing" "git.defalsify.org/vise.git/state" + "git.defalsify.org/vise.git/cache" ) func TestPhoneInput(t *testing.T) { @@ -87,3 +89,64 @@ func TestTargetInput(t *testing.T) { t.Fatal("expected true") } } + +func TestApplyTarget(t *testing.T) { + var err error + ctx := context.Background() + st := state.NewState(0) + st.Down("root") + st.Down("one") + st.Down("two") + ca := cache.NewCache() + rs := newTestResource(st) + rs.Lock() + b := NewLine(nil, INCMP, []string{"^", "0"}, nil, nil) + vm := NewVm(st, rs, ca, nil) + + st.SetInput([]byte("0")) + b, err = vm.Run(ctx, b) + if err != nil { + t.Fatal(err) + } + + st.Restart() + st.Down("foo") + b = NewLine(nil, INCMP, []string{"_", "0"}, nil, nil) + vm = NewVm(st, rs, ca, nil) + + st.SetInput([]byte("0")) + b, err = vm.Run(ctx, b) + if err != nil { + t.Fatal(err) + } + + st.Restart() + b = NewLine(nil, INCMP, []string{".", "0"}, nil, nil) + vm = NewVm(st, rs, ca, nil) + + st.SetInput([]byte("0")) + b, err = vm.Run(ctx, b) + if err != nil { + t.Fatal(err) + } + + st.Restart() + b = NewLine(nil, INCMP, []string{">", "0"}, nil, nil) + vm = NewVm(st, rs, ca, nil) + + st.SetInput([]byte("0")) + b, err = vm.Run(ctx, b) + if err != nil { + t.Fatal(err) + } + + st.Restart() + b = NewLine(nil, INCMP, []string{"<", "0"}, nil, nil) + vm = NewVm(st, rs, ca, nil) + + st.SetInput([]byte("0")) + b, err = vm.Run(ctx, b) + if err != nil { + t.Fatal(err) + } +}