go-vise

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

commit 26659e080a9ef296f1d9651d570c0aad263a6086
parent 0102efa7edb8c671b05e73b328c28ed3e947be63
Author: lash <dev@holbrook.no>
Date:   Wed, 11 Sep 2024 22:26:32 +0100

Add test coverage to input vm

Diffstat:
MMakefile | 2+-
Mvm/input_test.go | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -32,5 +32,5 @@ doc: cov: #go test -cover ./... -coverprofile=cover.out - go test -cover ./engine/... -coverprofile=cover.out + go test -cover ./vm/... -coverprofile=cover.out go tool cover -html=cover.out diff --git a/vm/input_test.go b/vm/input_test.go @@ -2,6 +2,8 @@ package vm import ( "testing" + + "git.defalsify.org/vise.git/state" ) func TestPhoneInput(t *testing.T) { @@ -31,4 +33,57 @@ func TestMenuInputs(t *testing.T) { if err != nil { t.Fatal(err) } -} +} + +func TestFalseInput(t *testing.T) { + err := ValidInput([]byte{0x0a}) + if err == nil { + t.Fatal("expected error") + } +} + +func TestTargetInput(t *testing.T) { + var err error + st := state.NewState(1) + _, err = CheckTarget([]byte(""), st) + if err == nil { + t.Fatal("expected error") + } + _, err = CheckTarget([]byte("_"), st) + if err == nil { + t.Fatal("expected error") + } + st.Down("foo") + v, err := CheckTarget([]byte("_"), st) + if err != nil { + t.Fatal(err) + } + if !v { + t.Fatal("expected true") + } + v, err = CheckTarget([]byte("<"), st) + if err != nil { + t.Fatal(err) + } + if v { + t.Fatal("expected false") + } + v, err = CheckTarget([]byte(">"), st) + if err != nil { + t.Fatal(err) + } + if !v { + t.Fatal("expected true") + } + v, err = CheckTarget([]byte("%"), st) + if err == nil { + t.Fatal("expected error") + } + v, err = CheckTarget([]byte("foo"), st) + if err != nil { + t.Fatal(err) + } + if !v { + t.Fatal("expected true") + } +}