go-vise

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

commit fddd13a8acdedc362917e09ee20b91681ecee218
parent 307fa6fcdc6b22db151721022bf45bc7be61a0f4
Author: lash <dev@holbrook.no>
Date:   Mon, 28 Oct 2024 20:18:57 +0000

Add lateral determination for state

Diffstat:
MCHANGELOG | 1+
Mstate/state.go | 11+++++++++++
Mstate/state_test.go | 28++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,4 +1,5 @@ - 0.2.1 + * Add lateral navigation indicator in State * Fix wrong key usage in postgres. * Add date updated field in postgres. - 0.2.0 diff --git a/state/state.go b/state/state.go @@ -42,6 +42,7 @@ type State struct { input []byte // Last input debug bool // Make string representation more human friendly invalid bool + lateral bool } // number of bytes necessary to represent a bitfield of the given size. @@ -211,6 +212,11 @@ func(st *State) Where() (string, uint16) { return st.ExecPath[l-1], st.SizeIdx } +// Lateral returns true if the last state move was Next() or Previous() +func(st *State) Lateral() bool { + return st.lateral +} + // Next moves to the next sink page index. func(st *State) Next() (uint16, error) { if len(st.ExecPath) == 0 { @@ -220,6 +226,7 @@ func(st *State) Next() (uint16, error) { s, idx := st.Where() logg.Debugf("next page", "location", s, "index", idx) st.Moves += 1 + st.lateral = true return st.SizeIdx, nil } @@ -241,6 +248,7 @@ func(st *State) Previous() (uint16, error) { s, idx := st.Where() logg.Debugf("previous page", "location", s, "index", idx) st.Moves += 1 + st.lateral = true return st.SizeIdx, nil } @@ -288,6 +296,7 @@ func(st *State) Down(input string) error { st.ExecPath = append(st.ExecPath, input) st.SizeIdx = 0 st.Moves += 1 + st.lateral = false return nil } @@ -312,6 +321,7 @@ func(st *State) Up() (string, error) { st.SizeIdx = 0 logg.Tracef("execpath after", "path", st.ExecPath) st.Moves += 1 + st.lateral = false return sym, nil } @@ -369,6 +379,7 @@ func(st *State) Restart() error { st.SizeIdx = 0 st.input = []byte{} st.ExecPath = st.ExecPath[:1] + st.lateral = false return err } diff --git a/state/state_test.go b/state/state_test.go @@ -481,3 +481,31 @@ func TestStateLanguage(t *testing.T) { t.Fatal("expected language set") } } + +func TestStateLateral(t *testing.T) { + st := NewState(0) + if st.Lateral() { + t.Fatal("expected not lateral") + } + st.Down("foo") + if st.Lateral() { + t.Fatal("expected not lateral") + } + st.Next() + if !st.Lateral() { + t.Fatal("expected lateral") + } + st.Down("bar") + if st.Lateral() { + t.Fatal("expected not lateral") + } + st.Next() + st.Previous() + if !st.Lateral() { + t.Fatal("expected lateral") + } + st.Restart() + if st.Lateral() { + t.Fatal("expected not lateral") + } +}