|
|
|
@ -2,6 +2,7 @@ package aliyun |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"math" |
|
|
|
|
"reflect" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/go-kratos/kratos/v2/log" |
|
|
|
@ -99,34 +100,44 @@ func TestLog(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestNewString(t *testing.T) { |
|
|
|
|
ptr := newString("") |
|
|
|
|
if kind := reflect.TypeOf(ptr).Kind(); kind != reflect.Ptr { |
|
|
|
|
t.Errorf("want type: %v, got type: %v", reflect.Ptr, kind) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestToString(t *testing.T) { |
|
|
|
|
tests := []struct { |
|
|
|
|
in interface{} |
|
|
|
|
out string |
|
|
|
|
name string |
|
|
|
|
in interface{} |
|
|
|
|
out string |
|
|
|
|
}{ |
|
|
|
|
{math.MaxFloat64, "17976931348623157000000000000000000000000000000000000" + |
|
|
|
|
"000000000000000000000000000000000000000000000000000000000000000000000000000" + |
|
|
|
|
"000000000000000000000000000000000000000000000000000000000000000000000000000" + |
|
|
|
|
"000000000000000000000000000000000000000000000000000000000000000000000000000" + |
|
|
|
|
"0000000000000000000000000000000"}, |
|
|
|
|
{math.MaxFloat32, "340282346638528860000000000000000000000"}, |
|
|
|
|
{1<<((32<<(^uint(0)>>63))-1) - 1, "9223372036854775807"}, |
|
|
|
|
{uint(1<<(32<<(^uint(0)>>63)) - 1), "-1"}, |
|
|
|
|
{math.MaxInt8, "127"}, |
|
|
|
|
{math.MaxUint8, "255"}, |
|
|
|
|
{math.MaxInt16, "32767"}, |
|
|
|
|
{math.MaxUint16, "65535"}, |
|
|
|
|
{math.MaxInt32, "2147483647"}, |
|
|
|
|
{math.MaxUint32, "4294967295"}, |
|
|
|
|
{math.MaxInt64, "9223372036854775807"}, |
|
|
|
|
{uint64(math.MaxUint64), "18446744073709551615"}, |
|
|
|
|
{"abc", "abc"}, |
|
|
|
|
{false, "false"}, |
|
|
|
|
{[]byte("abc"), "abc"}, |
|
|
|
|
{"float64", 6.66, "6.66"}, |
|
|
|
|
{"max float64", math.MaxFloat64, "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}, //nolint:lll
|
|
|
|
|
{"float32", float32(6.66), "6.66"}, |
|
|
|
|
{"max float32", math.MaxFloat32, "340282346638528860000000000000000000000"}, |
|
|
|
|
{"int", int(math.MaxInt64), "9223372036854775807"}, |
|
|
|
|
{"uint", uint(math.MaxUint64), "18446744073709551615"}, |
|
|
|
|
{"int8", math.MaxInt8, "127"}, |
|
|
|
|
{"uint8", math.MaxUint8, "255"}, |
|
|
|
|
{"int16", math.MaxInt16, "32767"}, |
|
|
|
|
{"uint16", math.MaxUint16, "65535"}, |
|
|
|
|
{"int32", math.MaxInt32, "2147483647"}, |
|
|
|
|
{"uint32", math.MaxUint32, "4294967295"}, |
|
|
|
|
{"int64", math.MaxInt64, "9223372036854775807"}, |
|
|
|
|
{"uint64", uint64(math.MaxUint64), "18446744073709551615"}, |
|
|
|
|
{"string", "abc", "abc"}, |
|
|
|
|
{"bool", false, "false"}, |
|
|
|
|
{"[]byte", []byte("abc"), "abc"}, |
|
|
|
|
{"struct", struct{ Name string }{}, `{"Name":""}`}, |
|
|
|
|
} |
|
|
|
|
for _, test := range tests { |
|
|
|
|
if toString(test.in) != test.out { |
|
|
|
|
t.Fatalf("want: %s, got: %s", test.out, toString(test.in)) |
|
|
|
|
} |
|
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
out := toString(test.in) |
|
|
|
|
if test.out != out { |
|
|
|
|
t.Fatalf("want: %s, got: %s", test.out, out) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|