1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-12 19:11:01 +00:00

Change meta to required, and refactor a bit to cover edge cases

This commit is contained in:
Joshua Santos
2016-06-30 10:32:53 -07:00
parent 84b6bef7d0
commit e0393b721c
2 changed files with 21 additions and 12 deletions

View File

@ -214,12 +214,14 @@ func TestRenderFormField(t *testing.T) {
func TestParseFormTag(t *testing.T) {
// create struct to contain field with different types of struct-tag `form`
type user struct {
All int `form:"name,text,年龄:"`
NoName int `form:",hidden,年龄:"`
OnlyLabel int `form:",,年龄:"`
OnlyName int `form:"name" id:"name" class:"form-name"`
Ignored int `form:"-"`
Required int `form:"name" meta:"true"`
All int `form:"name,text,年龄:"`
NoName int `form:",hidden,年龄:"`
OnlyLabel int `form:",,年龄:"`
OnlyName int `form:"name" id:"name" class:"form-name"`
Ignored int `form:"-"`
Required int `form:"name" required:"true"`
IgnoreRequired int `form:"name"`
NotRequired int `form:"name" required:"false"`
}
objT := reflect.TypeOf(&user{}).Elem()
@ -255,6 +257,16 @@ func TestParseFormTag(t *testing.T) {
t.Errorf("Form Tag containing only name and required was not correctly parsed.")
}
label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(6))
if !(name == "name" && required == false) {
t.Errorf("Form Tag containing only name and ignore required was not correctly parsed.")
}
label, name, fType, id, class, ignored, required = parseFormTag(objT.Field(7))
if !(name == "name" && required == false) {
t.Errorf("Form Tag containing only name and not required was not correctly parsed.")
}
}
func TestMapGet(t *testing.T) {