代码拉取完成,页面将自动刷新
package torm
import (
"reflect"
"testing"
)
type StructForField struct {
ID uint `torm:"primary_key" json:"id"`
Name string `torm:"column:name"`
Gender string `torm:"column:sex"`
Addr string
Balance float64 `torm:"NOT NULL;DEFAULT:0"`
Ignored interface{} `torm:"-"`
}
func TestNewField(t *testing.T) {
s := &StructForField{
ID: 1,
Name: "testing",
Gender: "F",
Balance: 366.36,
}
results := reflect.Indirect(reflect.ValueOf(s))
resultType := results.Type()
resultValue := results
fields := make(map[string]*Field)
for i := 0; i < resultType.NumField(); i++ {
fields[resultType.Field(i).Name] = NewField(resultValue.Field(i), resultType.Field(i))
}
f := fields["ID"]
if f.Name != "id" || f.Ignored || !f.Primary {
t.Errorf(`TestNewField: fields["ID"]'s name should be %s and cannot be ignored and is the primary key.`, f.Name)
}
err := f.SetValue(8)
if err != nil {
t.Error(err)
}
f = fields["Gender"]
if f.Name != "sex" {
t.Errorf(`TestNewField: fields["Gender"]'s name should be %s and cannot be ignored and is the primary key.`, f.Name)
}
f = fields["Ignored"]
if !f.Ignored {
t.Errorf(`TestNewField: fields["Ignored"]'s name should be ignored.`)
}
f = fields["Balance"]
_, ok := f.GetAttr("not null")
if !ok {
t.Errorf(`TestNewField: fields["Balance"]'s 'not null' attribution should find.`)
}
str, _ := f.GetAttr("default")
if str != "0" {
t.Errorf(`TestNewField: fields["Balance"]'s 'default' attribution should be '0'.`)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。