github.com/gogf/gf/v2@v2.7.4/internal/reflection/reflection_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 reflection_test
     8  
     9  import (
    10  	"reflect"
    11  	"testing"
    12  
    13  	"github.com/gogf/gf/v2/internal/reflection"
    14  	"github.com/gogf/gf/v2/test/gtest"
    15  )
    16  
    17  func Test_OriginValueAndKind(t *testing.T) {
    18  	gtest.C(t, func(t *gtest.T) {
    19  		var s = "s"
    20  		out := reflection.OriginValueAndKind(s)
    21  		t.Assert(out.InputKind, reflect.String)
    22  		t.Assert(out.OriginKind, reflect.String)
    23  	})
    24  	gtest.C(t, func(t *gtest.T) {
    25  		var s = "s"
    26  		out := reflection.OriginValueAndKind(&s)
    27  		t.Assert(out.InputKind, reflect.Ptr)
    28  		t.Assert(out.OriginKind, reflect.String)
    29  	})
    30  	gtest.C(t, func(t *gtest.T) {
    31  		var s []int
    32  		out := reflection.OriginValueAndKind(s)
    33  		t.Assert(out.InputKind, reflect.Slice)
    34  		t.Assert(out.OriginKind, reflect.Slice)
    35  	})
    36  	gtest.C(t, func(t *gtest.T) {
    37  		var s []int
    38  		out := reflection.OriginValueAndKind(&s)
    39  		t.Assert(out.InputKind, reflect.Ptr)
    40  		t.Assert(out.OriginKind, reflect.Slice)
    41  	})
    42  }
    43  
    44  func Test_OriginTypeAndKind(t *testing.T) {
    45  	gtest.C(t, func(t *gtest.T) {
    46  		var s = "s"
    47  		out := reflection.OriginTypeAndKind(s)
    48  		t.Assert(out.InputKind, reflect.String)
    49  		t.Assert(out.OriginKind, reflect.String)
    50  	})
    51  	gtest.C(t, func(t *gtest.T) {
    52  		var s = "s"
    53  		out := reflection.OriginTypeAndKind(&s)
    54  		t.Assert(out.InputKind, reflect.Ptr)
    55  		t.Assert(out.OriginKind, reflect.String)
    56  	})
    57  	gtest.C(t, func(t *gtest.T) {
    58  		var s []int
    59  		out := reflection.OriginTypeAndKind(s)
    60  		t.Assert(out.InputKind, reflect.Slice)
    61  		t.Assert(out.OriginKind, reflect.Slice)
    62  	})
    63  	gtest.C(t, func(t *gtest.T) {
    64  		var s []int
    65  		out := reflection.OriginTypeAndKind(&s)
    66  		t.Assert(out.InputKind, reflect.Ptr)
    67  		t.Assert(out.OriginKind, reflect.Slice)
    68  	})
    69  }