13 Star 36 Fork 9

Wendal / gor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
map2struct_test.go 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
Wendal 提交于 2013-03-05 09:17 . add: 开始重构, 先整理payload
package gor
import (
"reflect"
"testing"
)
func Test_Map2Struct(t *testing.T) {
m := map[string]interface{}{"permalink": "/:title/:year", "latest": 10}
post := &PostConfig{}
ToStruct(m, reflect.ValueOf(post))
if post.Permalink != m["permalink"].(string) {
t.Fail()
}
if post.Latest != m["latest"].(int) {
t.Fail()
}
}
func Test_Map2Struct2(t *testing.T) {
m := map[string]interface{}{"Theme": "facebook", "pages": map[string]interface{}{"permalink": "/wendal"}}
top := &TopConfig{}
ToStruct(m, reflect.ValueOf(top))
if top.Theme != "facebook" {
t.Fail()
}
if top.Pages.Permalink != "/wendal" {
t.Fail()
}
}
func Test_Map2Struct3(t *testing.T) {
m := map[string]interface{}{"title": "wendal", "navigation": []string{"admin.html", "user.html"}, "author": map[string]interface{}{"name": "wendal"}}
site := &SiteConfig{}
ToStruct(m, reflect.ValueOf(site))
if site.Title != "wendal" {
t.Fail()
}
if site.Navigation[0] != "admin.html" {
t.Fail()
}
if site.Navigation[1] != "user.html" {
t.Fail()
}
PrintJson(site)
}
Go
1
https://gitee.com/wendal/gor.git
git@gitee.com:wendal/gor.git
wendal
gor
gor
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891