aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/parse_test.go
diff options
context:
space:
mode:
authorrogeryk <rogeryk@outlook.com>2023-11-28 20:41:03 +0800
committerGopher Robot <gobot@golang.org>2024-02-24 21:59:12 +0000
commit08d9397170e5870b72a95233e8e4ec43d2d70e30 (patch)
tree766a6afaf628dcaa79587eb6d0f7074eeebc7e9b /src/text/template/parse/parse_test.go
parente0fc269f77af97f7cf33097d82f92ff7e08a2f06 (diff)
downloadgo-08d9397170e5870b72a95233e8e4ec43d2d70e30.tar.xz
text/template: add "else with" action
Add "else with" action will reduce the template complexity in some use cases(#57646). This action will be added: {{with pipeline}} T1 {{else with pipeline}} T0 {{end}}. Fixes #57646 Change-Id: I90ed546ab671805f753343b00bd3c9d1a1d5581d Reviewed-on: https://go-review.googlesource.com/c/go/+/545376 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/text/template/parse/parse_test.go')
-rw-r--r--src/text/template/parse/parse_test.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index 59e0a17412..faf226d1c3 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -244,6 +244,10 @@ var parseTests = []parseTest{
`{{with .X}}"hello"{{end}}`},
{"with with else", "{{with .X}}hello{{else}}goodbye{{end}}", noError,
`{{with .X}}"hello"{{else}}"goodbye"{{end}}`},
+ {"with with else with", "{{with .X}}hello{{else with .Y}}goodbye{{end}}", noError,
+ `{{with .X}}"hello"{{else}}{{with .Y}}"goodbye"{{end}}{{end}}`},
+ {"with else chain", "{{with .X}}X{{else with .Y}}Y{{else with .Z}}Z{{end}}", noError,
+ `{{with .X}}"X"{{else}}{{with .Y}}"Y"{{else}}{{with .Z}}"Z"{{end}}{{end}}{{end}}`},
// Trimming spaces.
{"trim left", "x \r\n\t{{- 3}}", noError, `"x"{{3}}`},
{"trim right", "{{3 -}}\n\n\ty", noError, `{{3}}"y"`},