github.com/wangyougui/gf/v2@v2.6.5/util/gconv/gconv_z_unit_ptr_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/wangyougui/gf.
     6  
     7  package gconv_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/test/gtest"
    13  	"github.com/wangyougui/gf/v2/util/gconv"
    14  )
    15  
    16  func Test_Ptr_Functions(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		var v interface{} = 1
    19  		t.AssertEQ(gconv.PtrAny(v), &v)
    20  	})
    21  	gtest.C(t, func(t *gtest.T) {
    22  		var v string = "1"
    23  		t.AssertEQ(gconv.PtrString(v), &v)
    24  	})
    25  	gtest.C(t, func(t *gtest.T) {
    26  		var v bool = true
    27  		t.AssertEQ(gconv.PtrBool(v), &v)
    28  	})
    29  	gtest.C(t, func(t *gtest.T) {
    30  		var v int = 1
    31  		t.AssertEQ(gconv.PtrInt(v), &v)
    32  	})
    33  	gtest.C(t, func(t *gtest.T) {
    34  		var v int8 = 1
    35  		t.AssertEQ(gconv.PtrInt8(v), &v)
    36  	})
    37  	gtest.C(t, func(t *gtest.T) {
    38  		var v int16 = 1
    39  		t.AssertEQ(gconv.PtrInt16(v), &v)
    40  	})
    41  	gtest.C(t, func(t *gtest.T) {
    42  		var v int32 = 1
    43  		t.AssertEQ(gconv.PtrInt32(v), &v)
    44  	})
    45  	gtest.C(t, func(t *gtest.T) {
    46  		var v int64 = 1
    47  		t.AssertEQ(gconv.PtrInt64(v), &v)
    48  	})
    49  	gtest.C(t, func(t *gtest.T) {
    50  		var v uint = 1
    51  		t.AssertEQ(gconv.PtrUint(v), &v)
    52  	})
    53  	gtest.C(t, func(t *gtest.T) {
    54  		var v uint8 = 1
    55  		t.AssertEQ(gconv.PtrUint8(v), &v)
    56  	})
    57  	gtest.C(t, func(t *gtest.T) {
    58  		var v uint16 = 1
    59  		t.AssertEQ(gconv.PtrUint16(v), &v)
    60  	})
    61  	gtest.C(t, func(t *gtest.T) {
    62  		var v uint32 = 1
    63  		t.AssertEQ(gconv.PtrUint32(v), &v)
    64  	})
    65  	gtest.C(t, func(t *gtest.T) {
    66  		var v uint64 = 1
    67  		t.AssertEQ(gconv.PtrUint64(v), &v)
    68  	})
    69  	gtest.C(t, func(t *gtest.T) {
    70  		var v float32 = 1.01
    71  		t.AssertEQ(gconv.PtrFloat32(v), &v)
    72  	})
    73  	gtest.C(t, func(t *gtest.T) {
    74  		var v float64 = 1.01
    75  		t.AssertEQ(gconv.PtrFloat64(v), &v)
    76  	})
    77  }