mirror of
https://gitee.com/johng/gf.git
synced 2024-12-10 19:31:47 +08:00
43 lines
857 B
Go
43 lines
857 B
Go
// Copyright 2020 gf Author(https://github.com/gogf/gf). 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 gvar_test
|
|
|
|
import (
|
|
"github.com/gogf/gf/container/gvar"
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/test/gtest"
|
|
"testing"
|
|
)
|
|
|
|
func Test_Struct(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
type StTest struct {
|
|
Test int
|
|
}
|
|
|
|
Kv := make(map[string]int, 1)
|
|
Kv["Test"] = 100
|
|
|
|
testObj := &StTest{}
|
|
|
|
objOne := gvar.New(Kv, true)
|
|
|
|
objOne.Struct(testObj)
|
|
|
|
t.Assert(testObj.Test, Kv["Test"])
|
|
})
|
|
gtest.C(t, func(t *gtest.T) {
|
|
type StTest struct {
|
|
Test int8
|
|
}
|
|
o := &StTest{}
|
|
v := gvar.New(g.Slice{"Test", "-25"})
|
|
v.Struct(o)
|
|
t.Assert(o.Test, -25)
|
|
})
|
|
}
|