2023-03-31 11:52:04 +02:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewStateFlags(t *testing.T) {
|
|
|
|
st := NewState(5, 0)
|
|
|
|
if len(st.Flags) != 1 {
|
|
|
|
t.Errorf("invalid state flag length: %v", len(st.Flags))
|
|
|
|
}
|
|
|
|
st = NewState(8, 0)
|
|
|
|
if len(st.Flags) != 1 {
|
|
|
|
t.Errorf("invalid state flag length: %v", len(st.Flags))
|
|
|
|
}
|
|
|
|
st = NewState(17, 0)
|
|
|
|
if len(st.Flags) != 3 {
|
|
|
|
t.Errorf("invalid state flag length: %v", len(st.Flags))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewStateCache(t *testing.T) {
|
|
|
|
st := NewState(17, 0)
|
|
|
|
if st.CacheSize != 0 {
|
|
|
|
t.Errorf("cache size not 0")
|
|
|
|
}
|
|
|
|
st = st.WithCacheSize(102525)
|
|
|
|
if st.CacheSize != 102525 {
|
|
|
|
t.Errorf("cache size not 102525")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-31 11:59:55 +02:00
|
|
|
|
|
|
|
func TestStateCacheUse(t *testing.T) {
|
|
|
|
st := NewState(17, 0)
|
2023-03-31 13:56:11 +02:00
|
|
|
st = st.WithCacheSize(10)
|
2023-03-31 11:59:55 +02:00
|
|
|
st.Enter("foo")
|
2023-03-31 13:56:11 +02:00
|
|
|
err := st.Add("bar", "baz")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = st.Add("inky", "pinky")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = st.Add("blinky", "clyde")
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected capacity error")
|
|
|
|
}
|
2023-03-31 11:59:55 +02:00
|
|
|
}
|