mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 20:28:17 +08:00
99 lines
2.2 KiB
Go
99 lines
2.2 KiB
Go
// Copyright 2019 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 gconv_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/test/gtest"
|
|
"github.com/gogf/gf/util/gconv"
|
|
)
|
|
|
|
func Test_Struct_Slice(t *testing.T) {
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []int
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []int32
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []int64
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []uint
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []uint32
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []uint64
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []float32
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
gtest.Case(t, func() {
|
|
type User struct {
|
|
Scores []float64
|
|
}
|
|
user := new(User)
|
|
array := g.Slice{1, 2, 3}
|
|
err := gconv.Struct(g.Map{"scores": array}, user)
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(user.Scores, array)
|
|
})
|
|
}
|