github.com/sandwich-go/boost@v1.3.29/xconv/uint_test.go (about)

     1  package xconv
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  )
     7  
     8  func TestUint(t *testing.T) {
     9  	Convey(`test uint`, t, func() {
    10  		for _, v := range []struct {
    11  			i  interface{}
    12  			is uint
    13  		}{
    14  			{nil, 0}, {3, 3}, {uint(3), 3}, {"3", 3}, {float32(3), 3}, {float64(3), 3},
    15  			{int8(3), 3}, {int16(3), 3}, {int32(3), 3}, {int64(3), 3},
    16  			{uint8(3), 3}, {uint16(3), 3}, {uint32(3), 3}, {uint64(3), 3},
    17  			{testInt{f1: 3, f2: 4}, 4},
    18  		} {
    19  			So(Uint(v.i), ShouldEqual, v.is)
    20  		}
    21  	})
    22  
    23  	Convey(`test uint8`, t, func() {
    24  		for _, v := range []struct {
    25  			i  interface{}
    26  			is uint8
    27  		}{
    28  			{nil, 0}, {3, 3}, {uint(3), 3}, {"3", 3}, {float32(3), 3}, {float64(3), 3},
    29  			{int8(3), 3}, {int16(3), 3}, {int32(3), 3}, {int64(3), 3},
    30  			{uint8(3), 3}, {uint16(3), 3}, {uint32(3), 3}, {uint64(3), 3},
    31  			{testInt{f1: 3, f2: 4}, 4},
    32  		} {
    33  			So(Uint8(v.i), ShouldEqual, v.is)
    34  		}
    35  	})
    36  
    37  	Convey(`test uint16`, t, func() {
    38  		for _, v := range []struct {
    39  			i  interface{}
    40  			is uint16
    41  		}{
    42  			{nil, 0}, {3, 3}, {uint(3), 3}, {"3", 3}, {float32(3), 3}, {float64(3), 3},
    43  			{int8(3), 3}, {int16(3), 3}, {int32(3), 3}, {int64(3), 3},
    44  			{uint8(3), 3}, {uint16(3), 3}, {uint32(3), 3}, {uint64(3), 3},
    45  			{testInt{f1: 3, f2: 4}, 4},
    46  		} {
    47  			So(Uint16(v.i), ShouldEqual, v.is)
    48  		}
    49  	})
    50  
    51  	Convey(`test uint32`, t, func() {
    52  		for _, v := range []struct {
    53  			i  interface{}
    54  			is int32
    55  		}{
    56  			{nil, 0}, {3, 3}, {uint(3), 3}, {"3", 3}, {float32(3), 3}, {float64(3), 3},
    57  			{int8(3), 3}, {int16(3), 3}, {int32(3), 3}, {int64(3), 3},
    58  			{uint8(3), 3}, {uint16(3), 3}, {uint32(3), 3}, {uint64(3), 3},
    59  			{testInt{f1: 3, f2: 4}, 4},
    60  		} {
    61  			So(Uint32(v.i), ShouldEqual, v.is)
    62  		}
    63  	})
    64  
    65  	Convey(`test uint64`, t, func() {
    66  		for _, v := range []struct {
    67  			i  interface{}
    68  			is uint64
    69  		}{
    70  			{nil, 0}, {3, 3}, {uint(3), 3}, {"3", 3}, {float32(3), 3}, {float64(3), 3},
    71  			{int8(3), 3}, {int16(3), 3}, {int32(3), 3}, {int64(3), 3},
    72  			{uint8(3), 3}, {uint16(3), 3}, {uint32(3), 3}, {uint64(3), 3},
    73  			{testInt{f1: 3, f2: 4}, 4},
    74  		} {
    75  			So(Uint64(v.i), ShouldEqual, v.is)
    76  		}
    77  	})
    78  }