Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
710f5b62
authored
2014-10-20 22:23:29 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix the test fun for pull request 873
1 parent
dbf944ad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
templatefunc.go
templatefunc_test.go
templatefunc.go
View file @
710f5b6
...
...
@@ -381,18 +381,18 @@ func RenderForm(obj interface{}) template.HTML {
// renderFormField returns a string containing HTML of a single form field.
func
renderFormField
(
label
,
name
,
fType
string
,
value
interface
{},
id
string
,
class
string
)
string
{
if
id
!=
""
{
id
=
"id=
\"
"
+
id
+
"
\"
"
id
=
"
id=
\"
"
+
id
+
"
\"
"
}
if
class
!=
""
{
class
=
"class=
\"
"
+
class
+
"
\"
"
class
=
"
class=
\"
"
+
class
+
"
\"
"
}
if
isValidForInput
(
fType
)
{
return
fmt
.
Sprintf
(
`%v<input
%v
%v name="%v" type="%v" value="%v">`
,
label
,
id
,
class
,
name
,
fType
,
value
)
return
fmt
.
Sprintf
(
`%v<input
%v
%v name="%v" type="%v" value="%v">`
,
label
,
id
,
class
,
name
,
fType
,
value
)
}
return
fmt
.
Sprintf
(
`%v<%v
%v
%v name="%v">%v</%v>`
,
label
,
fType
,
id
,
class
,
name
,
value
,
fType
)
return
fmt
.
Sprintf
(
`%v<%v
%v
%v name="%v">%v</%v>`
,
label
,
fType
,
id
,
class
,
name
,
value
,
fType
)
}
// isValidForInput checks if fType is a valid value for the `type` property of an HTML input element.
...
...
templatefunc_test.go
View file @
710f5b6
...
...
@@ -175,12 +175,12 @@ func TestRenderForm(t *testing.T) {
}
func
TestRenderFormField
(
t
*
testing
.
T
)
{
html
:=
renderFormField
(
"Label: "
,
"Name"
,
"text"
,
"Value"
)
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"
)
html
=
renderFormField
(
"Label: "
,
"Name"
,
"textarea"
,
"Value"
,
""
,
""
)
if
html
!=
`Label: <textarea name="Name">Value</textarea>`
{
t
.
Errorf
(
"Wrong html output for textarea: %v "
,
html
)
}
...
...
@@ -192,33 +192,34 @@ func TestParseFormTag(t *testing.T) {
All
int
`form:"name,text,年龄:"`
NoName
int
`form:",hidden,年龄:"`
OnlyLabel
int
`form:",,年龄:"`
OnlyName
int
`form:"name"`
OnlyName
int
`form:"name"
id:"name" class:"form-name"
`
Ignored
int
`form:"-"`
}
objT
:=
reflect
.
TypeOf
(
&
user
{})
.
Elem
()
label
,
name
,
fType
,
ignored
:=
parseFormTag
(
objT
.
Field
(
0
))
label
,
name
,
fType
,
i
d
,
class
,
i
gnored
:=
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
))
label
,
name
,
fType
,
i
d
,
class
,
i
gnored
=
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
))
label
,
name
,
fType
,
i
d
,
class
,
i
gnored
=
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
)
{
label
,
name
,
fType
,
id
,
class
,
ignored
=
parseFormTag
(
objT
.
Field
(
3
))
if
!
(
name
==
"name"
&&
label
==
"OnlyName: "
&&
fType
==
"text"
&&
ignored
==
false
&&
id
==
"name"
&&
class
==
"form-name"
)
{
t
.
Errorf
(
"Form Tag containing only name was not correctly parsed."
)
}
label
,
name
,
fType
,
ignored
=
parseFormTag
(
objT
.
Field
(
4
))
label
,
name
,
fType
,
i
d
,
class
,
i
gnored
=
parseFormTag
(
objT
.
Field
(
4
))
if
ignored
==
false
{
t
.
Errorf
(
"Form Tag that should be ignored was not correctly parsed."
)
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment