diff options
| author | Tim Cooper <tim.cooper@layeh.com> | 2017-09-26 21:14:03 -0300 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2017-10-17 02:06:15 +0000 |
| commit | 3be5d551801a97a76e236a2a53489b1c9c22e665 (patch) | |
| tree | 99281e70b044f736eef5def74773045673392747 /src/text/template/exec_test.go | |
| parent | 0b2cb89196967030ae005076f0166ad7d6024083 (diff) | |
| download | go-3be5d551801a97a76e236a2a53489b1c9c22e665.tar.xz | |
text/template: add break, continue actions in ranges
Adds the two range control actions "break" and "continue". They act the
same as the Go keywords break and continue, but are simplified in that
only the innermost range statement can be broken out of or continued.
Fixes #20531
Change-Id: I4412b3bbfd4dadb0ab74ae718e308c1ac7a0a1e9
Reviewed-on: https://go-review.googlesource.com/66410
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/exec_test.go')
| -rw-r--r-- | src/text/template/exec_test.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index d0cda6bd62..79b504f8a4 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -513,6 +513,10 @@ var execTests = []execTest{ {"declare in range", "{{range $x := .PSI}}<{{$foo:=$x}}{{$x}}>{{end}}", "<21><22><23>", tVal, true}, {"range count", `{{range $i, $x := count 5}}[{{$i}}]{{$x}}{{end}}`, "[0]a[1]b[2]c[3]d[4]e", tVal, true}, {"range nil count", `{{range $i, $x := count 0}}{{else}}empty{{end}}`, "empty", tVal, true}, + {"range quick break", `{{range .SI}}{{break}}{{.}}{{end}}`, "", tVal, true}, + {"range break after two", `{{range $i, $x := .SI}}{{if ge $i 2}}{{break}}{{end}}{{.}}{{end}}`, "34", tVal, true}, + {"range continue", `{{range .SI}}{{continue}}{{.}}{{end}}`, "", tVal, true}, + {"range continue condition", `{{range .SI}}{{if eq . 3 }}{{continue}}{{end}}{{.}}{{end}}`, "45", tVal, true}, // Cute examples. {"or as if true", `{{or .SI "slice is empty"}}`, "[3 4 5]", tVal, true}, |
