aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/parse_test.go
diff options
context:
space:
mode:
authorTim Cooper <tim.cooper@layeh.com>2017-09-26 21:14:03 -0300
committerRob Pike <r@golang.org>2017-10-17 02:06:15 +0000
commit3be5d551801a97a76e236a2a53489b1c9c22e665 (patch)
tree99281e70b044f736eef5def74773045673392747 /src/text/template/parse/parse_test.go
parent0b2cb89196967030ae005076f0166ad7d6024083 (diff)
downloadgo-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/parse/parse_test.go')
-rw-r--r--src/text/template/parse/parse_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index 81f14aca98..aade33ea48 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -218,6 +218,12 @@ var parseTests = []parseTest{
`{{range $x := .SI}}{{.}}{{end}}`},
{"range 2 vars", "{{range $x, $y := .SI}}{{.}}{{end}}", noError,
`{{range $x, $y := .SI}}{{.}}{{end}}`},
+ {"range []int with break", "{{range .SI}}{{break}}{{.}}{{end}}", noError,
+ `{{range .SI}}{{break}}{{.}}{{end}}`},
+ {"range []int with break in else", "{{range .SI}}{{range .SI}}{{.}}{{else}}{{break}}{{end}}{{end}}", noError,
+ `{{range .SI}}{{range .SI}}{{.}}{{else}}{{break}}{{end}}{{end}}`},
+ {"range []int with continue", "{{range .SI}}{{continue}}{{.}}{{end}}", noError,
+ `{{range .SI}}{{continue}}{{.}}{{end}}`},
{"constants", "{{range .SI 1 -3.2i true false 'a' nil}}{{end}}", noError,
`{{range .SI 1 -3.2i true false 'a' nil}}{{end}}`},
{"template", "{{template `x`}}", noError,
@@ -288,6 +294,12 @@ var parseTests = []parseTest{
{"empty pipeline", `{{printf "%d" ( ) }}`, hasError, ""},
// Missing pipeline in block
{"block definition", `{{block "foo"}}hello{{end}}`, hasError, ""},
+ // Invalid range control
+ {"break outside of range", `{{break}}`, hasError, ""},
+ {"break in range else, outside of range", `{{range .}}{{.}}{{else}}{{break}}{{end}}`, hasError, ""},
+ {"continue outside of range", `{{continue}}`, hasError, ""},
+ {"continue in range else, outside of range", `{{range .}}{{.}}{{else}}{{continue}}{{end}}`, hasError, ""},
+ {"additional break data", `{{range .}}{{break label}}{{end}}`, hasError, ""},
}
var builtins = map[string]interface{}{