Index: src/pkg/text/template/exec_test.go =================================================================== --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -273,6 +273,21 @@ {"&V{7777}.String()", "-{{.V1}}-", "-<7777>-", tVal, true}, {"(*V)(nil).String()", "-{{.V2}}-", "-nilV-", tVal, true}, + // Pass .Foo to function. + {"V0 | stringer", "-{{.V0 | stringer}}-", "-<6666>-", tVal, true}, + {"stringer V0", "-{{stringer .V0}}-", "-<6666>-", tVal, true}, + + // Invoke .Foo on result of function. + // Using variable works; without does not (unexpected bad character U+002E '.' in command). + {"V0 | echoer.Echo with var", "{{$E:=echoer}}-{{.V0 | $E.Echo}}-", "-{6666}-", tVal, true}, + {"echoer.Echo V0 with var", "{{$E:=echoer}}-{{$E.Echo .V0}}-", "-{6666}-", tVal, true}, + {"V0 | echoer.Echo", "-{{.V0 | echoer.Echo}}-", "-<6666>-", tVal, true}, + {"echoer.Echo V0", "-{{echoer.Echo .V0}}-", "-<6666>-", tVal, true}, + + // Check echoer.V0 (field reference) vs echoer .V0 (argument to function). + {"echoer.V0", "-{{echoer.V0}}-", "-0-", tVal, true}, + {"echoer .V0", "-{{echoer .V0}}-", "-{0}-", tVal, true}, + // Type with Error method. {"W{888}.Error()", "-{{.W0}}-", "-[888]-", tVal, true}, {"&W{999}.Error()", "-{{.W1}}-", "-[999]-", tVal, true}, @@ -528,6 +543,17 @@ return s.String() } +// Echoer implements Echo(x) = x. +type Echoer struct { + V0 int +} + +func (*Echoer) Echo(x interface{}) interface{} { return x } + +func echoer(args ...interface{}) *Echoer { + return &Echoer{} +} + func testExecute(execTests []execTest, template *Template, t *testing.T) { b := new(bytes.Buffer) funcs := FuncMap{ @@ -538,6 +564,7 @@ "vfunc": vfunc, "zeroArgs": zeroArgs, "stringer": stringer, + "echoer": echoer, } for _, test := range execTests { var tmpl *Template