diff options
| author | Rob Pike <r@golang.org> | 2013-08-28 14:43:56 +1000 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2013-08-28 14:43:56 +1000 |
| commit | 37cee77ac681654a20939faa047f11b308908902 (patch) | |
| tree | ed8aacc5c45910fd088d8f7f2cc7c33940010ddd /src/pkg/text/template/exec_test.go | |
| parent | cbea724378e1586cd92f1fffddcad61af893ba1d (diff) | |
| download | go-37cee77ac681654a20939faa047f11b308908902.tar.xz | |
text/template: allow {{else if ... }} to simplify if chains
The method is simple: the parser just parses
{{if A}}a{{else if B}}b{{end}}
to the same tree that would be produced by
{{if A}}a{{else}}{{if B}}b{{end}}{{end}}
Thus no changes are required in text/template itself
or in html/template, only in text/template/parse.
Fixes #6085
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13327043
Diffstat (limited to 'src/pkg/text/template/exec_test.go')
| -rw-r--r-- | src/pkg/text/template/exec_test.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index be1a2d23d8..bc8aee6f3c 100644 --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -374,6 +374,8 @@ var execTests = []execTest{ {"if map not unset", "{{if not .MXI.none}}ZERO{{else}}NON-ZERO{{end}}", "ZERO", tVal, true}, {"if $x with $y int", "{{if $x := true}}{{with $y := .I}}{{$x}},{{$y}}{{end}}{{end}}", "true,17", tVal, true}, {"if $x with $x int", "{{if $x := true}}{{with $x := .I}}{{$x}},{{end}}{{$x}}{{end}}", "17,true", tVal, true}, + {"if else if", "{{if false}}FALSE{{else if true}}TRUE{{end}}", "TRUE", tVal, true}, + {"if else chain", "{{if eq 1 3}}1{{else if eq 2 3}}2{{else if eq 3 3}}3{{end}}", "3", tVal, true}, // Print etc. {"print", `{{print "hello, print"}}`, "hello, print", tVal, true}, |
