add test case fot date & stringbool
Showing
1 changed file
with
17 additions
and
6 deletions
| ... | @@ -102,12 +102,14 @@ func TestHtmlunquote(t *testing.T) { | ... | @@ -102,12 +102,14 @@ func TestHtmlunquote(t *testing.T) { |
| 102 | 102 | ||
| 103 | func TestParseForm(t *testing.T) { | 103 | func TestParseForm(t *testing.T) { |
| 104 | type user struct { | 104 | type user struct { |
| 105 | Id int `form:"-"` | 105 | Id int `form:"-"` |
| 106 | tag string `form:"tag"` | 106 | tag string `form:"tag"` |
| 107 | Name interface{} `form:"username"` | 107 | Name interface{} `form:"username"` |
| 108 | Age int `form:"age,text"` | 108 | Age int `form:"age,text"` |
| 109 | Email string | 109 | Email string |
| 110 | Intro string `form:",textarea"` | 110 | Intro string `form:",textarea"` |
| 111 | StrBool bool `form:"strbool"` | ||
| 112 | Date time.Time `form:"date,2006-01-02"` | ||
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | u := user{} | 115 | u := user{} |
| ... | @@ -119,6 +121,8 @@ func TestParseForm(t *testing.T) { | ... | @@ -119,6 +121,8 @@ func TestParseForm(t *testing.T) { |
| 119 | "age": []string{"40"}, | 121 | "age": []string{"40"}, |
| 120 | "Email": []string{"test@gmail.com"}, | 122 | "Email": []string{"test@gmail.com"}, |
| 121 | "Intro": []string{"I am an engineer!"}, | 123 | "Intro": []string{"I am an engineer!"}, |
| 124 | "strbool": []string{"yes"}, | ||
| 125 | "date": []string{"2014-11-12"}, | ||
| 122 | } | 126 | } |
| 123 | if err := ParseForm(form, u); err == nil { | 127 | if err := ParseForm(form, u); err == nil { |
| 124 | t.Fatal("nothing will be changed") | 128 | t.Fatal("nothing will be changed") |
| ... | @@ -144,6 +148,13 @@ func TestParseForm(t *testing.T) { | ... | @@ -144,6 +148,13 @@ func TestParseForm(t *testing.T) { |
| 144 | if u.Intro != "I am an engineer!" { | 148 | if u.Intro != "I am an engineer!" { |
| 145 | t.Errorf("Intro should equal `I am an engineer!` but got `%v`", u.Intro) | 149 | t.Errorf("Intro should equal `I am an engineer!` but got `%v`", u.Intro) |
| 146 | } | 150 | } |
| 151 | if u.StrBool != true { | ||
| 152 | t.Errorf("strboll should equal `true`, but got `%v`", u.StrBool) | ||
| 153 | } | ||
| 154 | y, m, d := u.Date.Date() | ||
| 155 | if y != 2014 || m.String() != "November" || d != 12 { | ||
| 156 | t.Errorf("Date should equal `2014-11-12`, but got `%v`", u.Date.String()) | ||
| 157 | } | ||
| 147 | } | 158 | } |
| 148 | 159 | ||
| 149 | func TestRenderForm(t *testing.T) { | 160 | func TestRenderForm(t *testing.T) { | ... | ... |
-
Please register or sign in to post a comment