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

     1  package xconv
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  type testString struct {
    10  	f1 string
    11  }
    12  
    13  func (b testString) String() string { return b.f1 }
    14  
    15  func TestString(t *testing.T) {
    16  	Convey(`test string`, t, func() {
    17  		for _, v := range []struct {
    18  			i  interface{}
    19  			is string
    20  		}{
    21  			{i: nil}, {"3", "3"}, {[]byte("3"), "3"}, {3, "3"}, {uint(3), "3"},
    22  			{int8(3), "3"}, {int16(3), "3"}, {int32(3), "3"}, {int64(3), "3"},
    23  			{uint8(3), "3"}, {uint16(3), "3"}, {uint32(3), "3"}, {uint64(3), "3"},
    24  			{float32(3), "3"}, {float64(3), "3"}, {true, "true"}, {false, "false"},
    25  			{time.Time{}, ""}, {(*time.Time)(nil), ""},
    26  			{testString{"3"}, "3"}, {&testString{"3"}, "3"},
    27  			{map[string]string{"3": "3"}, `{"3":"3"}`},
    28  		} {
    29  			So(String(v.i), ShouldEqual, v.is)
    30  		}
    31  		So(String(func() {}), ShouldStartWith, "0x")
    32  	})
    33  }