From 08d9397170e5870b72a95233e8e4ec43d2d70e30 Mon Sep 17 00:00:00 2001 From: rogeryk Date: Tue, 28 Nov 2023 20:41:03 +0800 Subject: 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 Auto-Submit: Dmitri Shuralyov Reviewed-by: Cherry Mui Reviewed-by: Rob Pike Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor --- src/text/template/parse/parse_test.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/text/template/parse/parse_test.go') 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"`}, -- cgit v1.3-5-g45d5