github.com/zhongdalu/gf@v1.0.0/g/util/gconv/gconv_z_unit_basic_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 "testing" 11 12 "github.com/zhongdalu/gf/g/test/gtest" 13 "github.com/zhongdalu/gf/g/util/gconv" 14 ) 15 16 func Test_Basic(t *testing.T) { 17 gtest.Case(t, func() { 18 f32 := float32(123.456) 19 i64 := int64(1552578474888) 20 gtest.AssertEQ(gconv.Int(f32), int(123)) 21 gtest.AssertEQ(gconv.Int8(f32), int8(123)) 22 gtest.AssertEQ(gconv.Int16(f32), int16(123)) 23 gtest.AssertEQ(gconv.Int32(f32), int32(123)) 24 gtest.AssertEQ(gconv.Int64(f32), int64(123)) 25 gtest.AssertEQ(gconv.Int64(f32), int64(123)) 26 gtest.AssertEQ(gconv.Uint(f32), uint(123)) 27 gtest.AssertEQ(gconv.Uint8(f32), uint8(123)) 28 gtest.AssertEQ(gconv.Uint16(f32), uint16(123)) 29 gtest.AssertEQ(gconv.Uint32(f32), uint32(123)) 30 gtest.AssertEQ(gconv.Uint64(f32), uint64(123)) 31 gtest.AssertEQ(gconv.Float32(f32), float32(123.456)) 32 gtest.AssertEQ(gconv.Float64(i64), float64(i64)) 33 gtest.AssertEQ(gconv.Bool(f32), true) 34 gtest.AssertEQ(gconv.String(f32), "123.456") 35 gtest.AssertEQ(gconv.String(i64), "1552578474888") 36 }) 37 }