github.com/wangyougui/gf/v2@v2.6.5/util/gutil/gutil_z_unit_copy_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 gutil_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/frame/g"
    13  	"github.com/wangyougui/gf/v2/test/gtest"
    14  	"github.com/wangyougui/gf/v2/util/gutil"
    15  )
    16  
    17  func Test_Copy(t *testing.T) {
    18  	gtest.C(t, func(t *gtest.T) {
    19  		t.Assert(gutil.Copy(0), 0)
    20  		t.Assert(gutil.Copy(1), 1)
    21  		t.Assert(gutil.Copy("a"), "a")
    22  		t.Assert(gutil.Copy(nil), nil)
    23  	})
    24  	gtest.C(t, func(t *gtest.T) {
    25  		src := g.Map{
    26  			"k1": "v1",
    27  			"k2": "v2",
    28  		}
    29  		dst := gutil.Copy(src)
    30  		t.Assert(dst, src)
    31  
    32  		dst.(g.Map)["k3"] = "v3"
    33  		t.Assert(src, g.Map{
    34  			"k1": "v1",
    35  			"k2": "v2",
    36  		})
    37  		t.Assert(dst, g.Map{
    38  			"k1": "v1",
    39  			"k2": "v2",
    40  			"k3": "v3",
    41  		})
    42  	})
    43  }