From 3e5a7cf322892e59786a71a1395fe34bd89730fe Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 31 Mar 2023 23:25:05 +0100 Subject: [PATCH] Add flags byte array check --- go/state/state.go | 2 +- go/state/state_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/go/state/state.go b/go/state/state.go index 4e47f42..31a937a 100644 --- a/go/state/state.go +++ b/go/state/state.go @@ -52,7 +52,7 @@ func NewState(bitSize uint32) State { return st } -// SetFlag sets the flag at the given bit field index. +// SetFlag sets the flag at the given bit field index // // Returns true if bit state was changed. // diff --git a/go/state/state_test.go b/go/state/state_test.go index 43cda77..d7928f3 100644 --- a/go/state/state_test.go +++ b/go/state/state_test.go @@ -1,6 +1,7 @@ package state import ( + "bytes" "testing" ) @@ -85,6 +86,17 @@ func TestStateFlags(t *testing.T) { if v { t.Errorf("Expected change not to be set for bit 10") } + v, err = st.SetFlag(2) + if err != nil { + t.Error(err) + } + v, err = st.SetFlag(19) + if err != nil { + t.Error(err) + } + if !bytes.Equal(st.Flags[:3], []byte{0x04, 0x04, 0x08}) { + t.Errorf("Expected 0x020203, got %v", st.Flags[:3]) + } } //