aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/parse_test.go
diff options
context:
space:
mode:
authorAriel Mashraki <ariel@mashraki.co.il>2021-03-14 19:04:31 +0200
committerIan Lance Taylor <iant@golang.org>2021-04-19 16:49:40 +0000
commit5780ab4f605fdf0ca7f12ebc08e80d3ac170e98a (patch)
tree11cee00cc6e5fdc417df9fe49e181b62fbc33a36 /src/text/template/parse/parse_test.go
parent6b8e3e2d060b009fe92b39f7022445d96e225325 (diff)
downloadgo-5780ab4f605fdf0ca7f12ebc08e80d3ac170e98a.tar.xz
text/template/parse: add a mode to skip func-check on parsing
Following the discussion on #34652 and the proposal of #36911 (gopls), this CL adds an option to skip the function declartion check on parsing, in order to make it possible to parse arbitrary template text files and get their AST. Fixed #38627 Change-Id: Id1e0360fc726b49dcdd49716ce25563ebaae6c10 Reviewed-on: https://go-review.googlesource.com/c/go/+/301493 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/text/template/parse/parse_test.go')
-rw-r--r--src/text/template/parse/parse_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index 220f984777..c4585f6912 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -379,6 +379,22 @@ func TestParseWithComments(t *testing.T) {
}
}
+func TestDeferFuncCheck(t *testing.T) {
+ oldTextFormat := textFormat
+ textFormat = "%q"
+ defer func() { textFormat = oldTextFormat }()
+ tr := New("defer func check")
+ tr.Mode = DeferFuncCheck
+ tmpl, err := tr.Parse("{{fn 1 2}}", "", "", make(map[string]*Tree))
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ expected := "{{fn 1 2}}"
+ if result := tmpl.Root.String(); result != expected {
+ t.Errorf("got\n\t%v\nexpected\n\t%v", result, expected)
+ }
+}
+
type isEmptyTest struct {
name string
input string