github.com/gogf/gf/v2@v2.7.4/container/gvar/gvar_z_unit_slice_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 gvar_test 8 9 import ( 10 "testing" 11 12 "github.com/gogf/gf/v2/container/gvar" 13 "github.com/gogf/gf/v2/test/gtest" 14 ) 15 16 func TestVar_Ints(t *testing.T) { 17 gtest.C(t, func(t *gtest.T) { 18 var arr = []int{1, 2, 3, 4, 5} 19 objOne := gvar.New(arr, true) 20 t.Assert(objOne.Ints()[0], arr[0]) 21 }) 22 } 23 24 func TestVar_Uints(t *testing.T) { 25 gtest.C(t, func(t *gtest.T) { 26 var arr = []int{1, 2, 3, 4, 5} 27 objOne := gvar.New(arr, true) 28 t.Assert(objOne.Uints()[0], arr[0]) 29 }) 30 } 31 32 func TestVar_Int64s(t *testing.T) { 33 gtest.C(t, func(t *gtest.T) { 34 var arr = []int{1, 2, 3, 4, 5} 35 objOne := gvar.New(arr, true) 36 t.Assert(objOne.Int64s()[0], arr[0]) 37 }) 38 } 39 40 func TestVar_Uint64s(t *testing.T) { 41 gtest.C(t, func(t *gtest.T) { 42 var arr = []int{1, 2, 3, 4, 5} 43 objOne := gvar.New(arr, true) 44 t.Assert(objOne.Uint64s()[0], arr[0]) 45 }) 46 } 47 48 func TestVar_Floats(t *testing.T) { 49 gtest.C(t, func(t *gtest.T) { 50 var arr = []float64{1, 2, 3, 4, 5} 51 objOne := gvar.New(arr, true) 52 t.Assert(objOne.Floats()[0], arr[0]) 53 }) 54 } 55 56 func TestVar_Float32s(t *testing.T) { 57 gtest.C(t, func(t *gtest.T) { 58 var arr = []float32{1, 2, 3, 4, 5} 59 objOne := gvar.New(arr, true) 60 t.AssertEQ(objOne.Float32s(), arr) 61 }) 62 } 63 64 func TestVar_Float64s(t *testing.T) { 65 gtest.C(t, func(t *gtest.T) { 66 var arr = []float64{1, 2, 3, 4, 5} 67 objOne := gvar.New(arr, true) 68 t.AssertEQ(objOne.Float64s(), arr) 69 }) 70 } 71 72 func TestVar_Strings(t *testing.T) { 73 gtest.C(t, func(t *gtest.T) { 74 var arr = []string{"hello", "world"} 75 objOne := gvar.New(arr, true) 76 t.Assert(objOne.Strings()[0], arr[0]) 77 }) 78 } 79 80 func TestVar_Interfaces(t *testing.T) { 81 gtest.C(t, func(t *gtest.T) { 82 var arr = []int{1, 2, 3, 4, 5} 83 objOne := gvar.New(arr, true) 84 t.Assert(objOne.Interfaces(), arr) 85 }) 86 } 87 88 func TestVar_Slice(t *testing.T) { 89 gtest.C(t, func(t *gtest.T) { 90 var arr = []int{1, 2, 3, 4, 5} 91 objOne := gvar.New(arr, true) 92 t.Assert(objOne.Slice(), arr) 93 }) 94 } 95 96 func TestVar_Array(t *testing.T) { 97 gtest.C(t, func(t *gtest.T) { 98 var arr = []int{1, 2, 3, 4, 5} 99 objOne := gvar.New(arr, false) 100 t.Assert(objOne.Array(), arr) 101 }) 102 } 103 104 func TestVar_Vars(t *testing.T) { 105 gtest.C(t, func(t *gtest.T) { 106 var arr = []int{1, 2, 3, 4, 5} 107 objOne := gvar.New(arr, false) 108 t.Assert(len(objOne.Vars()), 5) 109 t.Assert(objOne.Vars()[0].Int(), 1) 110 t.Assert(objOne.Vars()[4].Int(), 5) 111 112 objEmpty := gvar.New([]int{}) 113 t.Assert(objEmpty.Vars(), nil) 114 }) 115 }