forked from beego/beego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package beego | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
func TestParseForm(t *testing.T) { | ||
type user struct { | ||
Id int | ||
tag string `form:tag` | ||
Name interface{} `form:"username"` | ||
Age int `form:"age"` | ||
Email string | ||
} | ||
|
||
u := user{} | ||
form := url.Values{ | ||
"tag": []string{"no"}, | ||
"username": []string{"test"}, | ||
"age": []string{"40"}, | ||
"Email": []string{"[email protected]"}, | ||
} | ||
if err := ParseForm(form, u); err == nil { | ||
t.Fatal("nothing will be changed") | ||
} | ||
if err := ParseForm(form, &u); err != nil { | ||
t.Fatal(err) | ||
} | ||
if u.Name.(string) != "test" { | ||
t.Error("should be equal") | ||
} | ||
if u.Age != 40 { | ||
t.Error("should be equal") | ||
} | ||
if u.Email != "[email protected]" { | ||
t.Error("should be equal") | ||
} | ||
} |