aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-05-20 11:33:36 -0400
committerRuss Cox <rsc@golang.org>2021-09-21 14:02:52 +0000
commit7d67f8d4354d864fcbe6b218b7f80bcdfde851c9 (patch)
treec965e575b56e7a25b3c8053bee7b05954e3dcd85 /src/text/template/exec_test.go
parent39e08c6cd75da72059a58f05eb500b48124d563e (diff)
downloadgo-7d67f8d4354d864fcbe6b218b7f80bcdfde851c9.tar.xz
text/template: implement short-circuit and, or
Making the builtin and and or functions use short-circuit evaluation was accepted as a proposal in April 2019, but we never got around to implementing it. Do that. Fixes #31103. Change-Id: Ia43d4a9a6b0ab814f2dd3471ebaca3e7bb1505cf Reviewed-on: https://go-review.googlesource.com/c/go/+/321490 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/exec_test.go')
-rw-r--r--src/text/template/exec_test.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
index ef521645a7..ae67b9334f 100644
--- a/src/text/template/exec_test.go
+++ b/src/text/template/exec_test.go
@@ -481,6 +481,10 @@ var execTests = []execTest{
{"not", "{{not true}} {{not false}}", "false true", nil, true},
{"and", "{{and false 0}} {{and 1 0}} {{and 0 true}} {{and 1 1}}", "false 0 0 1", nil, true},
{"or", "{{or 0 0}} {{or 1 0}} {{or 0 true}} {{or 1 1}}", "0 1 true 1", nil, true},
+ {"or short-circuit", "{{or 0 1 (die)}}", "1", nil, true},
+ {"and short-circuit", "{{and 1 0 (die)}}", "0", nil, true},
+ {"or short-circuit2", "{{or 0 0 (die)}}", "", nil, false},
+ {"and short-circuit2", "{{and 1 1 (die)}}", "", nil, false},
{"boolean if", "{{if and true 1 `hi`}}TRUE{{else}}FALSE{{end}}", "TRUE", tVal, true},
{"boolean if not", "{{if and true 1 `hi` | not}}TRUE{{else}}FALSE{{end}}", "FALSE", nil, true},
@@ -764,6 +768,7 @@ func testExecute(execTests []execTest, template *Template, t *testing.T) {
"add": add,
"count": count,
"dddArg": dddArg,
+ "die": func() bool { panic("die") },
"echo": echo,
"makemap": makemap,
"mapOfThree": mapOfThree,