From b9fdd67519a451c487fc5f15800dab5cf52d94f7 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 4 Nov 2014 16:39:17 +0800 Subject: [PATCH] add test case fot date & stringbool --- templatefunc_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/templatefunc_test.go b/templatefunc_test.go index 9a461c9f..3692a821 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -102,12 +102,14 @@ func TestHtmlunquote(t *testing.T) { func TestParseForm(t *testing.T) { type user struct { - Id int `form:"-"` - tag string `form:"tag"` - Name interface{} `form:"username"` - Age int `form:"age,text"` - Email string - Intro string `form:",textarea"` + Id int `form:"-"` + tag string `form:"tag"` + Name interface{} `form:"username"` + Age int `form:"age,text"` + Email string + Intro string `form:",textarea"` + StrBool bool `form:"strbool"` + Date time.Time `form:"date,2006-01-02"` } u := user{} @@ -119,6 +121,8 @@ func TestParseForm(t *testing.T) { "age": []string{"40"}, "Email": []string{"test@gmail.com"}, "Intro": []string{"I am an engineer!"}, + "strbool": []string{"yes"}, + "date": []string{"2014-11-12"}, } if err := ParseForm(form, u); err == nil { t.Fatal("nothing will be changed") @@ -144,6 +148,13 @@ func TestParseForm(t *testing.T) { if u.Intro != "I am an engineer!" { t.Errorf("Intro should equal `I am an engineer!` but got `%v`", u.Intro) } + if u.StrBool != true { + t.Errorf("strboll should equal `true`, but got `%v`", u.StrBool) + } + y, m, d := u.Date.Date() + if y != 2014 || m.String() != "November" || d != 12 { + t.Errorf("Date should equal `2014-11-12`, but got `%v`", u.Date.String()) + } } func TestRenderForm(t *testing.T) {