github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/enum/enum_test.go (about)

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