github.com/erda-project/erda-infra@v1.0.9/pkg/strutil/interface_test.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package strutil 16 17 import ( 18 "math" 19 "testing" 20 ) 21 22 func TestString(t *testing.T) { 23 tests := []struct { 24 name string 25 i interface{} 26 want string 27 }{ 28 {name: "int", i: 1, want: "1"}, 29 {name: "int8 min", i: int8(math.MinInt8), want: "-128"}, 30 {name: "int8 max", i: int8(math.MaxInt8), want: "127"}, 31 {name: "int32 min", i: int32(math.MinInt32), want: "-2147483648"}, 32 {name: "int32 max", i: int32(math.MaxInt32), want: "2147483647"}, 33 {name: "int64 min", i: int64(math.MinInt64), want: "-9223372036854775808"}, 34 {name: "int64 max", i: int64(math.MaxInt64), want: "9223372036854775807"}, 35 {name: "uint", i: uint(1), want: "1"}, 36 {name: "uint8 max", i: uint8(math.MaxUint8), want: "255"}, 37 {name: "uint32 max", i: uint32(math.MaxUint32), want: "4294967295"}, 38 {name: "uint64 max", i: uint64(math.MaxUint64), want: "18446744073709551615"}, 39 //{name: "float32", i: float32(1324555555), want: "1324555555"}, 40 {name: "float64", i: float64(132455555555555.1), want: "132455555555555.1"}, 41 {name: "[]byte", i: []byte{'a', 'b'}, want: "ab"}, 42 {name: "string", i: "ab", want: "ab"}, 43 } 44 for _, tt := range tests { 45 t.Run(tt.name, func(t *testing.T) { 46 if got := String(tt.i); got != tt.want { 47 t.Errorf("string() = %v, want %v", got, tt.want) 48 } 49 }) 50 } 51 }