gf/util/gutil/gutil_z_unit_copy_test.go

44 lines
888 B
Go
Executable File

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gutil_test
import (
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gutil"
)
func Test_Copy(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(gutil.Copy(0), 0)
t.Assert(gutil.Copy(1), 1)
t.Assert(gutil.Copy("a"), "a")
t.Assert(gutil.Copy(nil), nil)
})
gtest.C(t, func(t *gtest.T) {
src := g.Map{
"k1": "v1",
"k2": "v2",
}
dst := gutil.Copy(src)
t.Assert(dst, src)
dst.(g.Map)["k3"] = "v3"
t.Assert(src, g.Map{
"k1": "v1",
"k2": "v2",
})
t.Assert(dst, g.Map{
"k1": "v1",
"k2": "v2",
"k3": "v3",
})
})
}