mirror of
https://github.com/astaxie/beego.git
synced 2025-07-13 03:41:02 +00:00
beego: update licence& fix #669
This commit is contained in:
@ -1,21 +1,20 @@
|
||||
// Beego (http://beego.me/)
|
||||
|
||||
//
|
||||
// @description beego is an open-source, high-performance web framework for the Go programming language.
|
||||
|
||||
//
|
||||
// @link http://github.com/astaxie/beego for the canonical source repository
|
||||
|
||||
//
|
||||
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
||||
|
||||
//
|
||||
// @authors astaxie
|
||||
|
||||
package beego
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func TestSubstr(t *testing.T) {
|
||||
@ -141,17 +140,17 @@ func TestParseForm(t *testing.T) {
|
||||
|
||||
func TestRenderForm(t *testing.T) {
|
||||
type user struct {
|
||||
Id int `form:"-"`
|
||||
tag string `form:"tag"`
|
||||
Name interface{} `form:"username"`
|
||||
Age int `form:"age,text,年龄:"`
|
||||
Sex string
|
||||
Email []string
|
||||
Intro string `form:",textarea"`
|
||||
Id int `form:"-"`
|
||||
tag string `form:"tag"`
|
||||
Name interface{} `form:"username"`
|
||||
Age int `form:"age,text,年龄:"`
|
||||
Sex string
|
||||
Email []string
|
||||
Intro string `form:",textarea"`
|
||||
Ignored string `form:"-"`
|
||||
}
|
||||
|
||||
u := user{Name: "test", Intro: "Some Text"}
|
||||
u := user{Name: "test", Intro: "Some Text"}
|
||||
output := RenderForm(u)
|
||||
if output != template.HTML("") {
|
||||
t.Errorf("output should be empty but got %v", output)
|
||||
@ -168,51 +167,51 @@ func TestRenderForm(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRenderFormField(t *testing.T) {
|
||||
html := renderFormField("Label: ", "Name", "text", "Value")
|
||||
if html != `Label: <input name="Name" type="text" value="Value">` {
|
||||
t.Errorf("Wrong html output for input[type=text]: %v ", html)
|
||||
}
|
||||
html := renderFormField("Label: ", "Name", "text", "Value")
|
||||
if html != `Label: <input name="Name" type="text" value="Value">` {
|
||||
t.Errorf("Wrong html output for input[type=text]: %v ", html)
|
||||
}
|
||||
|
||||
html = renderFormField("Label: ", "Name", "textarea", "Value")
|
||||
if html != `Label: <textarea name="Name">Value</textarea>` {
|
||||
t.Errorf("Wrong html output for textarea: %v ", html)
|
||||
}
|
||||
html = renderFormField("Label: ", "Name", "textarea", "Value")
|
||||
if html != `Label: <textarea name="Name">Value</textarea>` {
|
||||
t.Errorf("Wrong html output for textarea: %v ", html)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFormTag(t *testing.T) {
|
||||
// create struct to contain field with different types of struct-tag `form`
|
||||
// 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"`
|
||||
Ignored int `form:"-"`
|
||||
}
|
||||
OnlyLabel int `form:",,年龄:"`
|
||||
OnlyName int `form:"name"`
|
||||
Ignored int `form:"-"`
|
||||
}
|
||||
|
||||
objT := reflect.TypeOf(&user{}).Elem()
|
||||
|
||||
label, name, fType, ignored := parseFormTag(objT.Field(0))
|
||||
if !(name == "name" && label == "年龄:" && fType == "text" && ignored == false) {
|
||||
label, name, fType, ignored := parseFormTag(objT.Field(0))
|
||||
if !(name == "name" && label == "年龄:" && fType == "text" && ignored == false) {
|
||||
t.Errorf("Form Tag with name, label and type was not correctly parsed.")
|
||||
}
|
||||
}
|
||||
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(1))
|
||||
if !(name == "NoName" && label == "年龄:" && fType == "hidden" && ignored == false) {
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(1))
|
||||
if !(name == "NoName" && label == "年龄:" && fType == "hidden" && ignored == false) {
|
||||
t.Errorf("Form Tag with label and type but without name was not correctly parsed.")
|
||||
}
|
||||
}
|
||||
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(2))
|
||||
if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && ignored == false) {
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(2))
|
||||
if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && ignored == false) {
|
||||
t.Errorf("Form Tag containing only label was not correctly parsed.")
|
||||
}
|
||||
}
|
||||
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(3))
|
||||
if !(name == "name" && label == "OnlyName: " && fType == "text" && ignored == false) {
|
||||
t.Errorf("Form Tag containing only name was not correctly parsed.")
|
||||
}
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(3))
|
||||
if !(name == "name" && label == "OnlyName: " && fType == "text" && ignored == false) {
|
||||
t.Errorf("Form Tag containing only name was not correctly parsed.")
|
||||
}
|
||||
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(4))
|
||||
if (ignored == false) {
|
||||
t.Errorf("Form Tag that should be ignored was not correctly parsed.")
|
||||
}
|
||||
label, name, fType, ignored = parseFormTag(objT.Field(4))
|
||||
if ignored == false {
|
||||
t.Errorf("Form Tag that should be ignored was not correctly parsed.")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user