github.com/zhongdalu/gf@v1.0.0/g/util/gconv/gconv_z_unit_string_test.go (about) 1 // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 package gconv_test 8 9 import ( 10 "github.com/zhongdalu/gf/g/test/gtest" 11 "github.com/zhongdalu/gf/g/util/gconv" 12 "testing" 13 ) 14 15 type stringStruct1 struct { 16 Name string 17 } 18 19 type stringStruct2 struct { 20 Name string 21 } 22 23 func (s *stringStruct1) String() string { 24 return s.Name 25 } 26 27 func Test_String(t *testing.T) { 28 gtest.Case(t, func() { 29 gtest.AssertEQ(gconv.String(int(123)), "123") 30 gtest.AssertEQ(gconv.String(int(-123)), "-123") 31 gtest.AssertEQ(gconv.String(int8(123)), "123") 32 gtest.AssertEQ(gconv.String(int8(-123)), "-123") 33 gtest.AssertEQ(gconv.String(int16(123)), "123") 34 gtest.AssertEQ(gconv.String(int16(-123)), "-123") 35 gtest.AssertEQ(gconv.String(int32(123)), "123") 36 gtest.AssertEQ(gconv.String(int32(-123)), "-123") 37 gtest.AssertEQ(gconv.String(int64(123)), "123") 38 gtest.AssertEQ(gconv.String(int64(-123)), "-123") 39 gtest.AssertEQ(gconv.String(int64(1552578474888)), "1552578474888") 40 gtest.AssertEQ(gconv.String(int64(-1552578474888)), "-1552578474888") 41 42 gtest.AssertEQ(gconv.String(uint(123)), "123") 43 gtest.AssertEQ(gconv.String(uint8(123)), "123") 44 gtest.AssertEQ(gconv.String(uint16(123)), "123") 45 gtest.AssertEQ(gconv.String(uint32(123)), "123") 46 gtest.AssertEQ(gconv.String(uint64(155257847488898765)), "155257847488898765") 47 48 gtest.AssertEQ(gconv.String(float32(123.456)), "123.456") 49 gtest.AssertEQ(gconv.String(float32(-123.456)), "-123.456") 50 gtest.AssertEQ(gconv.String(float64(1552578474888.456)), "1552578474888.456") 51 gtest.AssertEQ(gconv.String(float64(-1552578474888.456)), "-1552578474888.456") 52 53 gtest.AssertEQ(gconv.String(true), "true") 54 gtest.AssertEQ(gconv.String(false), "false") 55 56 gtest.AssertEQ(gconv.String([]byte("bytes")), "bytes") 57 58 gtest.AssertEQ(gconv.String(stringStruct1{"john"}), `{"Name":"john"}`) 59 gtest.AssertEQ(gconv.String(&stringStruct1{"john"}), "john") 60 61 gtest.AssertEQ(gconv.String(stringStruct2{"john"}), `{"Name":"john"}`) 62 gtest.AssertEQ(gconv.String(&stringStruct2{"john"}), `{"Name":"john"}`) 63 }) 64 }