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

add funcmap

This commit is contained in:
miraclesu
2013-07-24 01:20:24 +08:00
parent aba1728bc3
commit 4c6163baa0
5 changed files with 128 additions and 33 deletions

View File

@ -56,3 +56,19 @@ func TestGetValidFuncs(t *testing.T) {
t.Error("Range funcs should be got")
}
}
func TestCall(t *testing.T) {
u := user{Name: "test", Age: 180}
tf := reflect.TypeOf(u)
var vfs []ValidFunc
var err error
f, _ := tf.FieldByName("Age")
if vfs, err = getValidFuncs(f); err != nil {
t.Fatal(err)
}
valid := &Validation{}
funcs.Call(vfs[1].Name, valid, u.Age, vfs[1].Params[0], vfs[1].Params[1], vfs[1].Name)
if len(valid.Errors) != 1 {
t.Error("age out of range should be has an error")
}
}