Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
08d3f5e2
Commit
08d3f5e2
authored
Jan 15, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: look inside interface values
R=r CC=golang-dev
https://golang.org/cl/186169
parent
d6054fcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
src/pkg/template/template.go
src/pkg/template/template.go
+3
-0
src/pkg/template/template_test.go
src/pkg/template/template_test.go
+20
-0
No files found.
src/pkg/template/template.go
View file @
08d3f5e2
...
...
@@ -723,6 +723,9 @@ func (t *Template) varValue(name string, st *state) reflect.Value {
}
return
t
.
varValue
(
name
,
st
.
parent
)
}
if
iface
,
ok
:=
field
.
(
*
reflect
.
InterfaceValue
);
ok
&&
!
iface
.
IsNil
()
{
field
=
iface
.
Elem
()
}
return
field
}
...
...
src/pkg/template/template_test.go
View file @
08d3f5e2
...
...
@@ -44,6 +44,7 @@ type S struct {
innermap
U
stringmap
map
[
string
]
string
bytes
[]
byte
iface
interface
{}
}
func
(
s
*
S
)
pointerMethod
()
string
{
return
"ptrmethod!"
}
...
...
@@ -353,6 +354,24 @@ var tests = []*Test{
out
:
"stringresult
\n
"
+
"stringresult
\n
"
,
},
// Interface values
&
Test
{
in
:
"{iface}"
,
out
:
"[1 2 3]"
,
},
&
Test
{
in
:
"{.repeated section iface}{@}{.alternates with} {.end}"
,
out
:
"1 2 3"
,
},
&
Test
{
in
:
"{.section iface}{@}{.end}"
,
out
:
"[1 2 3]"
,
},
}
func
TestAll
(
t
*
testing
.
T
)
{
...
...
@@ -379,6 +398,7 @@ func TestAll(t *testing.T) {
s
.
stringmap
[
"stringkey1"
]
=
"stringresult"
// the same value so repeated section is order-independent
s
.
stringmap
[
"stringkey2"
]
=
"stringresult"
s
.
bytes
=
strings
.
Bytes
(
"hello"
)
s
.
iface
=
[]
int
{
1
,
2
,
3
}
var
buf
bytes
.
Buffer
for
_
,
test
:=
range
tests
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment