github.com/sandwich-go/boost@v1.3.29/xcontainer/syncmap/gen_int_int8_test.go (about)

     1  // Code generated by gotemplate. DO NOT EDIT.
     2  
     3  // syncmap 提供了一个同步的映射实现,允许安全并发的访问
     4  package syncmap
     5  
     6  import (
     7  	"errors"
     8  
     9  	. "github.com/smartystreets/goconvey/convey"
    10  
    11  	"testing"
    12  )
    13  
    14  func TestIntInt8(t *testing.T) {
    15  	Convey("test sync map", t, func() {
    16  		for _, tr := range []*IntInt8{NewIntInt8()} {
    17  			So(tr.Len(), ShouldBeZeroValue)
    18  			var k, v = __formatKTypeToIntInt8(3), __formatVTypeToIntInt8(4)
    19  			So(tr.Len(), ShouldEqual, 0)
    20  			tr.Store(k, v)
    21  			v1, ok := tr.Load(k)
    22  			So(ok, ShouldBeTrue)
    23  			So(v1, ShouldEqual, v)
    24  
    25  			So(tr.Keys(), ShouldResemble, []int{__formatKTypeToIntInt8(3)})
    26  			So(tr.Get(__formatKTypeToIntInt8(3)), ShouldEqual, __formatVTypeToIntInt8(4))
    27  			So(tr.Contains(__formatKTypeToIntInt8(3)), ShouldBeTrue)
    28  
    29  			tr.Store(__formatKTypeToIntInt8(4), __formatVTypeToIntInt8(5))
    30  			tr.Store(__formatKTypeToIntInt8(5), __formatVTypeToIntInt8(6))
    31  			ol := tr.Len()
    32  			tr.DeleteMultiple(__formatKTypeToIntInt8(4), __formatKTypeToIntInt8(5))
    33  			So(tr.Len(), ShouldEqual, ol-2)
    34  
    35  			ol = tr.Len()
    36  			tr.Store(__formatKTypeToIntInt8(4), __formatVTypeToIntInt8(5))
    37  			tr.Store(__formatKTypeToIntInt8(5), __formatVTypeToIntInt8(6))
    38  			vl, ok := tr.LoadAndDelete(__formatKTypeToIntInt8(4))
    39  			So(vl, ShouldEqual, __formatVTypeToIntInt8(5))
    40  			So(ok, ShouldBeTrue)
    41  			So(tr.Len(), ShouldEqual, ol+1)
    42  
    43  			tr.Store(__formatKTypeToIntInt8(4), __formatVTypeToIntInt8(5))
    44  			fge := []func(key int, cf func(key int) (int8, error)) (value int8, loaded bool, err error){tr.GetOrSetFuncErrorLock}
    45  			defv, defv2 := __formatVTypeToIntInt8(6), __formatVTypeToIntInt8(7)
    46  			for _, f := range fge {
    47  				v, l, e := f(__formatKTypeToIntInt8(6), func(key int) (int8, error) {
    48  					return defv, nil
    49  				})
    50  				So(v, ShouldEqual, defv)
    51  				So(l, ShouldBeFalse)
    52  				So(e, ShouldBeNil)
    53  
    54  				v, l, e = f(__formatKTypeToIntInt8(7), func(key int) (int8, error) {
    55  					return defv2, errors.New("")
    56  				})
    57  				So(v, ShouldEqual, defv2)
    58  				So(l, ShouldBeFalse)
    59  				So(e, ShouldNotBeNil)
    60  			}
    61  			fg := []func(key int, cf func(key int) int8) (value int8, loaded bool){tr.GetOrSetFuncLock}
    62  			for _, f := range fg {
    63  				v, l := f(__formatKTypeToIntInt8(7), func(key int) int8 {
    64  					return defv2
    65  				})
    66  				So(v, ShouldEqual, defv2)
    67  				So(l, ShouldBeFalse)
    68  			}
    69  
    70  			v, ok = tr.LoadOrStore(__formatKTypeToIntInt8(8), __formatVTypeToIntInt8(9))
    71  			So(v, ShouldEqual, __formatVTypeToIntInt8(9))
    72  			So(ok, ShouldBeFalse)
    73  
    74  			So(func() {
    75  				tr.Range(func(key int, value int8) bool {
    76  					return true
    77  				})
    78  			}, ShouldNotPanic)
    79  
    80  		}
    81  	})
    82  }