diff options
| author | Rob Pike <r@golang.org> | 2012-02-15 16:05:34 +1100 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-02-15 16:05:34 +1100 |
| commit | aca8071fd53fc4f60771fe816b1e7c20c5c674fb (patch) | |
| tree | 480dc6a9c76dee9dd43f79f08c5ccbe4ea0957bb /src/pkg/text/template/exec_test.go | |
| parent | 9a445600334fcd4e856206b0223f8b85c71f7999 (diff) | |
| download | go-aca8071fd53fc4f60771fe816b1e7c20c5c674fb.tar.xz | |
text/template: evaluate function fields
Just an oversight they didn't work and easy to address.
Fixes #3025.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5656059
Diffstat (limited to 'src/pkg/text/template/exec_test.go')
| -rw-r--r-- | src/pkg/text/template/exec_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index 9bb55e48aa..159cf5100d 100644 --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -59,6 +59,8 @@ type T struct { PI *int PSI *[]int NIL *int + // Function (not method) + Func func(...string) string // Template to test evaluation of templates. Tmpl *Template } @@ -118,6 +120,7 @@ var tVal = &T{ Err: errors.New("erroozle"), PI: newInt(23), PSI: newIntSlice(21, 22, 23), + Func: func(s ...string) string { return fmt.Sprint("<", strings.Join(s, "+"), ">") }, Tmpl: Must(New("x").Parse("test template")), // "x" is the value of .X } @@ -297,8 +300,13 @@ var execTests = []execTest{ "{{with $x := .}}{{with .SI}}{{$.GetU.TrueFalse $.True}}{{end}}{{end}}", "true", tVal, true}, + // Function call + {".Func", "-{{.Func}}-", "-<>-", tVal, true}, + {".Func2", "-{{.Func `he` `llo`}}-", "-<he+llo>-", tVal, true}, + // Pipelines. {"pipeline", "-{{.Method0 | .Method2 .U16}}-", "-Method2: 16 M0-", tVal, true}, + {"pipeline func", "-{{.Func `llo` | .Func `he` }}-", "-<he+<llo>>-", tVal, true}, // If. {"if true", "{{if true}}TRUE{{end}}", "TRUE", tVal, true}, |
