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/exec_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/text/template/exec_test.go') diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index e607fd3bee..8fdd9280f2 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -569,6 +569,8 @@ var execTests = []execTest{ {"with $x struct.U.V", "{{with $x := $}}{{$x.U.V}}{{end}}", "v", tVal, true}, {"with variable and action", "{{with $x := $}}{{$y := $.U.V}}{{$y}}{{end}}", "v", tVal, true}, {"with on typed nil interface value", "{{with .NonEmptyInterfaceTypedNil}}TRUE{{ end }}", "", tVal, true}, + {"with else with", "{{with 0}}{{.}}{{else with true}}{{.}}{{end}}", "true", tVal, true}, + {"with else with chain", "{{with 0}}{{.}}{{else with false}}{{.}}{{else with `notempty`}}{{.}}{{end}}", "notempty", tVal, true}, // Range. {"range []int", "{{range .SI}}-{{.}}-{{end}}", "-3--4--5-", tVal, true}, -- cgit v1.3-5-g9baa