github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/enumeration/enum_test.go (about) 1 package enumeration_test 2 3 import ( 4 "testing" 5 6 "github.com/octohelm/storage/internal/testutil" 7 "github.com/octohelm/storage/pkg/enumeration" 8 ) 9 10 func TestScanEnum(t *testing.T) { 11 cases := []struct { 12 offset int 13 values []interface{} 14 expect []int 15 }{ 16 { 17 -3, 18 []interface{}{ 19 nil, 20 []byte("-3"), 21 "-2", 22 int(-1), 23 int8(0), 24 int16(1), 25 int32(2), 26 int64(3), 27 uint(4), 28 uint8(5), 29 uint16(6), 30 uint32(7), 31 uint64(8), 32 }, 33 []int{ 34 0, 35 0, 36 1, 37 2, 38 3, 39 4, 40 5, 41 6, 42 7, 43 8, 44 9, 45 10, 46 11, 47 }, 48 }, 49 } 50 51 for _, c := range cases { 52 for i, v := range c.values { 53 n, err := enumeration.ScanIntEnumStringer(v, c.offset) 54 testutil.Expect(t, err, testutil.Be[error](nil)) 55 testutil.Expect(t, n, testutil.Equal(c.expect[i])) 56 } 57 } 58 }