github.com/gogf/gf/v2@v2.7.4/util/gconv/gconv_z_unit_interfaces_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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/gogf/gf. 6 7 package gconv_test 8 9 import ( 10 "testing" 11 12 "github.com/gogf/gf/v2/test/gtest" 13 "github.com/gogf/gf/v2/util/gconv" 14 ) 15 16 var interfacesTests = []struct { 17 value interface{} 18 expect []interface{} 19 }{ 20 {[]bool{true, false}, []interface{}{true, false}}, 21 22 {[]int{0, 1, 2}, []interface{}{0, 1, 2}}, 23 {[]int8{0, 1, 2}, []interface{}{0, 1, 2}}, 24 {[]int16{0, 1, 2}, []interface{}{0, 1, 2}}, 25 {[]int32{0, 1, 2}, []interface{}{0, 1, 2}}, 26 {[]int64{0, 1, 2}, []interface{}{0, 1, 2}}, 27 28 {[]uint{0, 1, 2}, []interface{}{0, 1, 2}}, 29 {[]uint8{0, 1, 2}, []interface{}{0, 1, 2}}, 30 {[]uint16{0, 1, 2}, []interface{}{0, 1, 2}}, 31 {[]uint32{0, 1, 2}, []interface{}{0, 1, 2}}, 32 {[]uint64{0, 1, 2}, []interface{}{0, 1, 2}}, 33 34 {[]uintptr{0, 1, 2}, []interface{}{0, 1, 2}}, 35 {[]rune{0, 1, 2}, []interface{}{0, 1, 2}}, 36 37 {[]float32{0, 1, 2}, []interface{}{0, 1, 2}}, 38 {[]float64{0, 1, 2}, []interface{}{0, 1, 2}}, 39 40 {[][]byte{[]byte("0"), []byte("1"), []byte("2")}, 41 []interface{}{[]byte("0"), []byte("1"), []byte("2")}}, 42 {[]string{"0", "1", "2"}, []interface{}{"0", "1", "2"}}, 43 44 {[]complex64{0, 1, 2}, []interface{}{0 + 0i, 1 + 0i, 2 + 0i}}, 45 {[]complex128{0, 1, 2}, []interface{}{0 + 0i, 1 + 0i, 2 + 0i}}, 46 47 {[]interface{}{0, 1, 2}, []interface{}{0, 1, 2}}, 48 {nil, nil}, 49 } 50 51 func TestInterfaces(t *testing.T) { 52 gtest.C(t, func(t *gtest.T) { 53 for _, test := range interfacesTests { 54 if test.value == nil { 55 t.AssertNil(gconv.Interfaces(test.value)) 56 continue 57 } 58 t.AssertEQ(gconv.Interfaces(test.value), test.expect) 59 } 60 }) 61 }