summaryrefslogtreecommitdiffstats
path: root/tpl/internal
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-12-02 13:23:25 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-12-03 13:12:58 +0100
commitd90e37e0c6e812f9913bf256c9c81aa05b7a08aa (patch)
tree7b1b14464eefec1188ca2eed53c64e4823453cc9 /tpl/internal
parent32471b57bde51c55a15dbf1db75d6e5f7232c347 (diff)
all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
Diffstat (limited to 'tpl/internal')
-rw-r--r--tpl/internal/go_templates/fmtsort/sort_test.go3
-rw-r--r--tpl/internal/go_templates/htmltemplate/content_test.go2
-rw-r--r--tpl/internal/go_templates/htmltemplate/css.go6
-rw-r--r--tpl/internal/go_templates/htmltemplate/escape_test.go2
-rw-r--r--tpl/internal/go_templates/htmltemplate/example_test.go2
-rw-r--r--tpl/internal/go_templates/htmltemplate/js.go1
-rw-r--r--tpl/internal/go_templates/htmltemplate/js_test.go3
-rw-r--r--tpl/internal/go_templates/htmltemplate/transition.go6
-rw-r--r--tpl/internal/go_templates/htmltemplate/transition_test.go1
-rw-r--r--tpl/internal/go_templates/testenv/testenv.go3
-rw-r--r--tpl/internal/go_templates/testenv/testenv_windows.go6
-rw-r--r--tpl/internal/go_templates/texttemplate/example_test.go2
-rw-r--r--tpl/internal/go_templates/texttemplate/exec.go5
-rw-r--r--tpl/internal/go_templates/texttemplate/exec_test.go50
-rw-r--r--tpl/internal/go_templates/texttemplate/hugo_template.go1
-rw-r--r--tpl/internal/go_templates/texttemplate/hugo_template_test.go1
-rw-r--r--tpl/internal/go_templates/texttemplate/multi_test.go35
-rw-r--r--tpl/internal/go_templates/texttemplate/parse/node.go1
-rw-r--r--tpl/internal/go_templates/texttemplate/parse/parse.go2
-rw-r--r--tpl/internal/go_templates/texttemplate/parse/parse_test.go360
-rw-r--r--tpl/internal/go_templates/texttemplate/template.go3
-rw-r--r--tpl/internal/templatefuncsRegistry.go2
22 files changed, 322 insertions, 175 deletions
diff --git a/tpl/internal/go_templates/fmtsort/sort_test.go b/tpl/internal/go_templates/fmtsort/sort_test.go
index 364c5bf6d..189c693cc 100644
--- a/tpl/internal/go_templates/fmtsort/sort_test.go
+++ b/tpl/internal/go_templates/fmtsort/sort_test.go
@@ -6,11 +6,12 @@ package fmtsort_test
import (
"fmt"
- "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
"math"
"reflect"
"strings"
"testing"
+
+ "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
)
var compareTests = [][]reflect.Value{
diff --git a/tpl/internal/go_templates/htmltemplate/content_test.go b/tpl/internal/go_templates/htmltemplate/content_test.go
index b5de701d3..f2c5c5ed1 100644
--- a/tpl/internal/go_templates/htmltemplate/content_test.go
+++ b/tpl/internal/go_templates/htmltemplate/content_test.go
@@ -427,7 +427,7 @@ func TestStringer(t *testing.T) {
if err := tmpl.Execute(b, s); err != nil {
t.Fatal(err)
}
- var expect = "string=3"
+ expect := "string=3"
if b.String() != expect {
t.Errorf("expected %q got %q", expect, b.String())
}
diff --git a/tpl/internal/go_templates/htmltemplate/css.go b/tpl/internal/go_templates/htmltemplate/css.go
index eb92fc92b..b006a0718 100644
--- a/tpl/internal/go_templates/htmltemplate/css.go
+++ b/tpl/internal/go_templates/htmltemplate/css.go
@@ -210,8 +210,10 @@ var cssReplacementTable = []string{
'}': `\7d`,
}
-var expressionBytes = []byte("expression")
-var mozBindingBytes = []byte("mozbinding")
+var (
+ expressionBytes = []byte("expression")
+ mozBindingBytes = []byte("mozbinding")
+)
// cssValueFilter allows innocuous CSS values in the output including CSS
// quantities (10px or 25%), ID or class literals (#foo, .bar), keyword values
diff --git a/tpl/internal/go_templates/htmltemplate/escape_test.go b/tpl/internal/go_templates/htmltemplate/escape_test.go
index 075db4e13..ee5421cc8 100644
--- a/tpl/internal/go_templates/htmltemplate/escape_test.go
+++ b/tpl/internal/go_templates/htmltemplate/escape_test.go
@@ -891,7 +891,6 @@ func TestEscapeSet(t *testing.T) {
t.Errorf("want\n\t%q\ngot\n\t%q", test.want, got)
}
}
-
}
func TestErrors(t *testing.T) {
@@ -1088,7 +1087,6 @@ func TestErrors(t *testing.T) {
// Check that we get the same error if we call Execute again.
if err := tmpl.Execute(buf, nil); err == nil || err.Error() != got {
t.Errorf("input=%q: unexpected error on second call %q", test.input, err)
-
}
}
}
diff --git a/tpl/internal/go_templates/htmltemplate/example_test.go b/tpl/internal/go_templates/htmltemplate/example_test.go
index a93b8d2fb..ee1cbbb4a 100644
--- a/tpl/internal/go_templates/htmltemplate/example_test.go
+++ b/tpl/internal/go_templates/htmltemplate/example_test.go
@@ -82,7 +82,6 @@ func Example() {
// <div><strong>no rows</strong></div>
// </body>
// </html>
-
}
func Example_autoescaping() {
@@ -123,7 +122,6 @@ func Example_escape() {
// \"Fran \u0026 Freddie\'s Diner\" \u003Ctasty@example.com\u003E
// \"Fran \u0026 Freddie\'s Diner\"32\u003Ctasty@example.com\u003E
// %22Fran+%26+Freddie%27s+Diner%2232%3Ctasty%40example.com%3E
-
}
func ExampleTemplate_Delims() {
diff --git a/tpl/internal/go_templates/htmltemplate/js.go b/tpl/internal/go_templates/htmltemplate/js.go
index cfd413461..f19e774c7 100644
--- a/tpl/internal/go_templates/htmltemplate/js.go
+++ b/tpl/internal/go_templates/htmltemplate/js.go
@@ -337,6 +337,7 @@ var jsStrNormReplacementTable = []string{
'<': `\u003c`,
'>': `\u003e`,
}
+
var jsRegexpReplacementTable = []string{
0: `\u0000`,
'\t': `\t`,
diff --git a/tpl/internal/go_templates/htmltemplate/js_test.go b/tpl/internal/go_templates/htmltemplate/js_test.go
index e15087f0f..f7ee3cfaa 100644
--- a/tpl/internal/go_templates/htmltemplate/js_test.go
+++ b/tpl/internal/go_templates/htmltemplate/js_test.go
@@ -206,7 +206,8 @@ func TestJSStrEscaper(t *testing.T) {
{"<!--", `\u003c!--`},
{"-->", `--\u003e`},
// From https://code.google.com/p/doctype/wiki/ArticleUtf7
- {"+ADw-script+AD4-alert(1)+ADw-/script+AD4-",
+ {
+ "+ADw-script+AD4-alert(1)+ADw-/script+AD4-",
`\u002bADw-script\u002bAD4-alert(1)\u002bADw-\/script\u002bAD4-`,
},
// Invalid UTF-8 sequence
diff --git a/tpl/internal/go_templates/htmltemplate/transition.go b/tpl/internal/go_templates/htmltemplate/transition.go
index 06df67933..5ba7f8017 100644
--- a/tpl/internal/go_templates/htmltemplate/transition.go
+++ b/tpl/internal/go_templates/htmltemplate/transition.go
@@ -41,8 +41,10 @@ var transitionFunc = [...]func(context, []byte) (context, int){
stateError: tError,
}
-var commentStart = []byte("<!--")
-var commentEnd = []byte("-->")
+var (
+ commentStart = []byte("<!--")
+ commentEnd = []byte("-->")
+)
// tText is the context transition function for the text state.
func tText(c context, s []byte) (context, int) {
diff --git a/tpl/internal/go_templates/htmltemplate/transition_test.go b/tpl/internal/go_templates/htmltemplate/transition_test.go
index 00b0ff6ca..c3257a839 100644
--- a/tpl/internal/go_templates/htmltemplate/transition_test.go
+++ b/tpl/internal/go_templates/htmltemplate/transition_test.go
@@ -42,7 +42,6 @@ func TestFindEndTag(t *testing.T) {
}
func BenchmarkTemplateSpecialTags(b *testing.B) {
-
r := struct {
Name, Gift string
}{"Aunt Mildred", "bone china tea set"}
diff --git a/tpl/internal/go_templates/testenv/testenv.go b/tpl/internal/go_templates/testenv/testenv.go
index 90044570d..7c46089f5 100644
--- a/tpl/internal/go_templates/testenv/testenv.go
+++ b/tpl/internal/go_templates/testenv/testenv.go
@@ -13,7 +13,6 @@ package testenv
import (
"errors"
"flag"
- "github.com/gohugoio/hugo/tpl/internal/go_templates/cfg"
"os"
"os/exec"
"path/filepath"
@@ -22,6 +21,8 @@ import (
"strings"
"sync"
"testing"
+
+ "github.com/gohugoio/hugo/tpl/internal/go_templates/cfg"
)
// Builder reports the name of the builder running this test
diff --git a/tpl/internal/go_templates/testenv/testenv_windows.go b/tpl/internal/go_templates/testenv/testenv_windows.go
index eb8d6ac16..f9e7da5a7 100644
--- a/tpl/internal/go_templates/testenv/testenv_windows.go
+++ b/tpl/internal/go_templates/testenv/testenv_windows.go
@@ -12,8 +12,10 @@ import (
"syscall"
)
-var symlinkOnce sync.Once
-var winSymlinkErr error
+var (
+ symlinkOnce sync.Once
+ winSymlinkErr error
+)
func initWinHasSymlink() {
tmpdir, err := ioutil.TempDir("", "symtest")
diff --git a/tpl/internal/go_templates/texttemplate/example_test.go b/tpl/internal/go_templates/texttemplate/example_test.go
index f192cac4f..09555c95a 100644
--- a/tpl/internal/go_templates/texttemplate/example_test.go
+++ b/tpl/internal/go_templates/texttemplate/example_test.go
@@ -34,7 +34,7 @@ Josie
Name, Gift string
Attended bool
}
- var recipients = []Recipient{
+ recipients := []Recipient{
{"Aunt Mildred", "bone china tea set", true},
{"Uncle John", "moleskin pants", false},
{"Cousin Rodney", "", false},
diff --git a/tpl/internal/go_templates/texttemplate/exec.go b/tpl/internal/go_templates/texttemplate/exec.go
index 879cd0884..db533d735 100644
--- a/tpl/internal/go_templates/texttemplate/exec.go
+++ b/tpl/internal/go_templates/texttemplate/exec.go
@@ -6,12 +6,13 @@ package template
import (
"fmt"
- "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
- "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
"io"
"reflect"
"runtime"
"strings"
+
+ "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"
+ "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
)
// maxExecDepth specifies the maximum stack depth of templates within
diff --git a/tpl/internal/go_templates/texttemplate/exec_test.go b/tpl/internal/go_templates/texttemplate/exec_test.go
index 940a1de6a..cc79d2143 100644
--- a/tpl/internal/go_templates/texttemplate/exec_test.go
+++ b/tpl/internal/go_templates/texttemplate/exec_test.go
@@ -318,12 +318,16 @@ var execTests = []execTest{
{"$.U.V", "{{$.U.V}}", "v", tVal, true},
{"declare in action", "{{$x := $.U.V}}{{$x}}", "v", tVal, true},
{"simple assignment", "{{$x := 2}}{{$x = 3}}{{$x}}", "3", tVal, true},
- {"nested assignment",
+ {
+ "nested assignment",
"{{$x := 2}}{{if true}}{{$x = 3}}{{end}}{{$x}}",
- "3", tVal, true},
- {"nested assignment changes the last declaration",
+ "3", tVal, true,
+ },
+ {
+ "nested assignment changes the last declaration",
"{{$x := 1}}{{if true}}{{$x := 2}}{{if true}}{{$x = 3}}{{end}}{{end}}{{$x}}",
- "1", tVal, true},
+ "1", tVal, true,
+ },
// Type with String method.
{"V{6666}.String()", "-{{.V0}}-", "-<6666>-", tVal, true},
@@ -370,15 +374,21 @@ var execTests = []execTest{
{".Method3(nil constant)", "-{{.Method3 nil}}-", "-Method3: <nil>-", tVal, true},
{".Method3(nil value)", "-{{.Method3 .MXI.unset}}-", "-Method3: <nil>-", tVal, true},
{"method on var", "{{if $x := .}}-{{$x.Method2 .U16 $x.X}}{{end}}-", "-Method2: 16 x-", tVal, true},
- {"method on chained var",
+ {
+ "method on chained var",
"{{range .MSIone}}{{if $.U.TrueFalse $.True}}{{$.U.TrueFalse $.True}}{{else}}WRONG{{end}}{{end}}",
- "true", tVal, true},
- {"chained method",
+ "true", tVal, true,
+ },
+ {
+ "chained method",
"{{range .MSIone}}{{if $.GetU.TrueFalse $.True}}{{$.U.TrueFalse $.True}}{{else}}WRONG{{end}}{{end}}",
- "true", tVal, true},
- {"chained method on variable",
+ "true", tVal, true,
+ },
+ {
+ "chained method on variable",
"{{with $x := .}}{{with .SI}}{{$.GetU.TrueFalse $.True}}{{end}}{{end}}",
- "true", tVal, true},
+ "true", tVal, true,
+ },
{".NilOKFunc not nil", "{{call .NilOKFunc .PI}}", "false", tVal, true},
{".NilOKFunc nil", "{{call .NilOKFunc nil}}", "true", tVal, true},
{"method on nil value from slice", "-{{range .}}{{.Method1 1234}}{{end}}-", "-1234-", tSliceOfNil, true},
@@ -464,10 +474,14 @@ var execTests = []execTest{
{"printf lots", `{{printf "%d %s %g %s" 127 "hello" 7-3i .Method0}}`, "127 hello (7-3i) M0", tVal, true},
// HTML.
- {"html", `{{html "<script>alert(\"XSS\");</script>"}}`,
- "&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;", nil, true},
- {"html pipeline", `{{printf "<script>alert(\"XSS\");</script>" | html}}`,
- "&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;", nil, true},
+ {
+ "html", `{{html "<script>alert(\"XSS\");</script>"}}`,
+ "&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;", nil, true,
+ },
+ {
+ "html pipeline", `{{printf "<script>alert(\"XSS\");</script>" | html}}`,
+ "&lt;script&gt;alert(&#34;XSS&#34;);&lt;/script&gt;", nil, true,
+ },
{"html", `{{html .PS}}`, "a string", tVal, true},
{"html typed nil", `{{html .NIL}}`, "&lt;nil&gt;", tVal, true},
{"html untyped nil", `{{html .Empty0}}`, "&lt;no value&gt;", tVal, true},
@@ -825,7 +839,7 @@ var delimPairs = []string{
func TestDelims(t *testing.T) {
const hello = "Hello, world"
- var value = struct{ Str string }{hello}
+ value := struct{ Str string }{hello}
for i := 0; i < len(delimPairs); i += 2 {
text := ".Str"
left := delimPairs[i+0]
@@ -848,7 +862,7 @@ func TestDelims(t *testing.T) {
if err != nil {
t.Fatalf("delim %q text %q parse err %s", left, text, err)
}
- var b = new(bytes.Buffer)
+ b := new(bytes.Buffer)
err = tmpl.Execute(b, value)
if err != nil {
t.Fatalf("delim %q exec err %s", left, err)
@@ -949,7 +963,7 @@ const treeTemplate = `
`
func TestTree(t *testing.T) {
- var tree = &Tree{
+ tree := &Tree{
1,
&Tree{
2, &Tree{
@@ -1195,7 +1209,7 @@ var cmpTests = []cmpTest{
func TestComparison(t *testing.T) {
b := new(bytes.Buffer)
- var cmpStruct = struct {
+ cmpStruct := struct {
Uthree, Ufour uint
NegOne, Three int
Ptr, NilPtr *int
diff --git a/tpl/internal/go_templates/texttemplate/hugo_template.go b/tpl/internal/go_templates/texttemplate/hugo_template.go
index 7cd6df0fb..0dc6331c7 100644
--- a/tpl/internal/go_templates/texttemplate/hugo_template.go
+++ b/tpl/internal/go_templates/texttemplate/hugo_template.go
@@ -77,7 +77,6 @@ func (t *executer) Execute(p Preparer, wr io.Writer, data interface{}) error {
}
return tmpl.executeWithState(state, value)
-
}
// Prepare returns a template ready for execution.
diff --git a/tpl/internal/go_templates/texttemplate/hugo_template_test.go b/tpl/internal/go_templates/texttemplate/hugo_template_test.go
index 98a2575eb..90bb09315 100644
--- a/tpl/internal/go_templates/texttemplate/hugo_template_test.go
+++ b/tpl/internal/go_templates/texttemplate/hugo_template_test.go
@@ -85,5 +85,4 @@ Method: {{ .Hello1 "v1" }}
c.Assert(got, qt.Contains, "hello hugo")
c.Assert(got, qt.Contains, "Map: av")
c.Assert(got, qt.Contains, "Method: v2 v1")
-
}
diff --git a/tpl/internal/go_templates/texttemplate/multi_test.go b/tpl/internal/go_templates/texttemplate/multi_test.go
index 7323be379..569a45dbb 100644
--- a/tpl/internal/go_templates/texttemplate/multi_test.go
+++ b/tpl/internal/go_templates/texttemplate/multi_test.go
@@ -11,8 +11,9 @@ package template
import (
"bytes"
"fmt"
- "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
"testing"
+
+ "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
)
const (
@@ -29,22 +30,32 @@ type multiParseTest struct {
}
var multiParseTests = []multiParseTest{
- {"empty", "", noError,
+ {
+ "empty", "", noError,
nil,
- nil},
- {"one", `{{define "foo"}} FOO {{end}}`, noError,
+ nil,
+ },
+ {
+ "one", `{{define "foo"}} FOO {{end}}`, noError,
[]string{"foo"},
- []string{" FOO "}},
- {"two", `{{define "foo"}} FOO {{end}}{{define "bar"}} BAR {{end}}`, noError,
+ []string{" FOO "},
+ },
+ {
+ "two", `{{define "foo"}} FOO {{end}}{{define "bar"}} BAR {{end}}`, noError,
[]string{"foo", "bar"},
- []string{" FOO ", " BAR "}},
+ []string{" FOO ", " BAR "},
+ },
// errors
- {"missing end", `{{define "foo"}} FOO `, hasError,
+ {
+ "missing end", `{{define "foo"}} FOO `, hasError,
+ nil,
+ nil,
+ },
+ {
+ "malformed name", `{{define "foo}} FOO `, hasError,
nil,
- nil},
- {"malformed name", `{{define "foo}} FOO `, hasError,
nil,
- nil},
+ },
}
func TestMultiParse(t *testing.T) {
@@ -400,7 +411,7 @@ func TestIssue19294(t *testing.T) {
// by the contents of "stylesheet", but if the internal map associating
// names with templates is built in the wrong order, the empty block
// looks non-empty and this doesn't happen.
- var inlined = map[string]string{
+ inlined := map[string]string{
"stylesheet": `{{define "stylesheet"}}stylesheet{{end}}`,
"xhtml": `{{block "stylesheet" .}}{{end}}`,
}
diff --git a/tpl/internal/go_templates/texttemplate/parse/node.go b/tpl/internal/go_templates/texttemplate/parse/node.go
index 1c116ea6f..dee67a2ed 100644
--- a/tpl/internal/go_templates/texttemplate/parse/node.go
+++ b/tpl/internal/go_templates/texttemplate/parse/node.go
@@ -249,7 +249,6 @@ func (a *ActionNode) tree() *Tree {
func (a *ActionNode) Copy() Node {
return a.tr.newAction(a.Pos, a.Line, a.Pipe.CopyPipe())
-
}
// CommandNode holds a command (a pipeline inside an evaluating action).
diff --git a/tpl/internal/go_templates/texttemplate/parse/parse.go b/tpl/internal/go_templates/texttemplate/parse/parse.go
index c9b80f4a2..7a58c5788 100644
--- a/tpl/internal/go_templates/texttemplate/parse/parse.go
+++ b/tpl/internal/go_templates/texttemplate/parse/parse.go
@@ -453,7 +453,7 @@ func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int
var next Node
list, next = t.itemList()
switch next.Type() {
- case nodeEnd: //done
+ case nodeEnd: // done
case nodeElse:
if allowElseIf {
// Special case for "else if". If the "else" is followed immediately by an "if",
diff --git a/tpl/internal/go_templates/texttemplate/parse/parse_test.go b/tpl/internal/go_templates/texttemplate/parse/parse_test.go
index 79e7bb5ae..97511190d 100644
--- a/tpl/internal/go_templates/texttemplate/parse/parse_test.go
+++ b/tpl/internal/go_templates/texttemplate/parse/parse_test.go
@@ -178,70 +178,134 @@ const (
)
var parseTests = []parseTest{
- {"empty", "", noError,
- ``},
- {"comment", "{{/*\n\n\n*/}}", noError,
- ``},
- {"spaces", " \t\n", noError,
- `" \t\n"`},
- {"text", "some text", noError,
- `"some text"`},
- {"emptyAction", "{{}}", hasError,
- `{{}}`},
- {"field", "{{.X}}", noError,
- `{{.X}}`},
- {"simple command", "{{printf}}", noError,
- `{{printf}}`},
- {"$ invocation", "{{$}}", noError,
- "{{$}}"},
- {"variable invocation", "{{with $x := 3}}{{$x 23}}{{end}}", noError,
- "{{with $x := 3}}{{$x 23}}{{end}}"},
- {"variable with fields", "{{$.I}}", noError,
- "{{$.I}}"},
- {"multi-word command", "{{printf `%d` 23}}", noError,
- "{{printf `%d` 23}}"},
- {"pipeline", "{{.X|.Y}}", noError,
- `{{.X | .Y}}`},
- {"pipeline with decl", "{{$x := .X|.Y}}", noError,
- `{{$x := .X | .Y}}`},
- {"nested pipeline", "{{.X (.Y .Z) (.A | .B .C) (.E)}}", noError,
- `{{.X (.Y .Z) (.A | .B .C) (.E)}}`},
- {"field applied to parentheses", "{{(.Y .Z).Field}}", noError,
- `{{(.Y .Z).Field}}`},
- {"simple if", "{{if .X}}hello{{end}}", noError,
- `{{if .X}}"hello"{{end}}`},
- {"if with else", "{{if .X}}true{{else}}false{{end}}", noError,
- `{{if .X}}"true"{{else}}"false"{{end}}`},
- {"if with else if", "{{if .X}}true{{else if .Y}}false{{end}}", noError,
- `{{if .X}}"true"{{else}}{{if .Y}}"false"{{end}}{{end}}`},
- {"if else chain", "+{{if .X}}X{{else if .Y}}Y{{else if .Z}}Z{{end}}+", noError,
- `"+"{{if .X}}"X"{{else}}{{if .Y}}"Y"{{else}}{{if .Z}}"Z"{{end}}{{end}}{{end}}"+"`},
- {"simple range", "{{range .X}}hello{{end}}", noError,
- `{{range .X}}"hello"{{end}}`},
- {"chained field range", "{{range .X.Y.Z}}hello{{end}}", noError,
- `{{range .X.Y.Z}}"hello"{{end}}`},
- {"nested range", "{{range .X}}hello{{range .Y}}goodbye{{end}}{{end}}", noError,
- `{{range .X}}"hello"{{range .Y}}"goodbye"{{end}}{{end}}`},
- {"range with else", "{{range .X}}true{{else}}false{{end}}", noError,
- `{{range .X}}"true"{{else}}"false"{{end}}`},
- {"range over pipeline", "{{range .X|.M}}true{{else}}false{{end}}", noError,
- `{{range .X | .M}}"true"{{else}}"false"{{end}}`},
- {"range []int", "{{range .SI}}{{.}}{{end}}", noError,
- `{{range .SI}}{{.}}{{end}}`},
- {"range 1 var", "{{range $x := .SI}}{{.}}{{end}}", noError,
- `{{range $x := .SI}}{{.}}{{end}}`},
- {"range 2 vars", "{{range $x, $y := .SI}}{{.}}{{end}}", noError,
- `{{range $x, $y := .SI}}{{.}}{{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,
- `{{template "x"}}`},
- {"template with arg", "{{template `x` .Y}}", noError,
- `{{template "x" .Y}}`},
- {"with", "{{with .X}}hello{{end}}", noError,
- `{{with .X}}"hello"{{end}}`},
- {"with with else", "{{with .X}}hello{{else}}goodbye{{end}}", noError,
- `{{with .X}}"hello"{{else}}"goodbye"{{end}}`},
+ {
+ "empty", "", noError,
+ ``,
+ },
+ {
+ "comment", "{{/*\n\n\n*/}}", noError,
+ ``,
+ },
+ {
+ "spaces", " \t\n", noError,
+ `" \t\n"`,
+ },
+ {
+ "text", "some text", noError,
+ `"some text"`,
+ },
+ {
+ "emptyAction", "{{}}", hasError,
+ `{{}}`,
+ },
+ {
+ "field", "{{.X}}", noError,
+ `{{.X}}`,
+ },
+ {
+ "simple command", "{{printf}}", noError,
+ `{{printf}}`,
+ },
+ {
+ "$ invocation", "{{$}}", noError,
+ "{{$}}",
+ },
+ {
+ "variable invocation", "{{with $x := 3}}{{$x 23}}{{end}}", noError,
+ "{{with $x := 3}}{{$x 23}}{{end}}",
+ },
+ {
+ "variable with fields", "{{$.I}}", noError,
+ "{{$.I}}",
+ },
+ {
+ "multi-word command", "{{printf `%d` 23}}", noError,
+ "{{printf `%d` 23}}",
+ },
+ {
+ "pipeline", "{{.X|.Y}}", noError,
+ `{{.X | .Y}}`,
+ },
+ {
+ "pipeline with decl", "{{$x := .X|.Y}}", noError,
+ `{{$x := .X | .Y}}`,
+ },
+ {
+ "nested pipeline", "{{.X (.Y .Z) (.A | .B .C) (.E)}}", noError,
+ `{{.X (.Y .Z) (.A | .B .C) (.E)}}`,
+ },
+ {
+ "field applied to parentheses", "{{(.Y .Z).Field}}", noError,
+ `{{(.Y .Z).Field}}`,
+ },
+ {
+ "simple if", "{{if .X}}hello{{end}}", noError,
+ `{{if .X}}"hello"{{end}}`,
+ },
+ {
+ "if with else", "{{if .X}}true{{else}}false{{end}}", noError,
+ `{{if .X}}"true"{{else}}"false"{{end}}`,
+ },
+ {
+ "if with else if", "{{if .X}}true{{else if .Y}}false{{end}}", noError,
+ `{{if .X}}"true"{{else}}{{if .Y}}"false"{{end}}{{end}}`,
+ },
+ {
+ "if else chain", "+{{if .X}}X{{else if .Y}}Y{{else if .Z}}Z{{end}}+", noError,
+ `"+"{{if .X}}"X"{{else}}{{if .Y}}"Y"{{else}}{{if .Z}}"Z"{{end}}{{end}}{{end}}"+"`,
+ },
+ {
+ "simple range", "{{range .X}}hello{{end}}", noError,
+ `{{range .X}}"hello"{{end}}`,
+ },
+ {
+ "chained field range", "{{range .X.Y.Z}}hello{{end}}", noError,
+ `{{range .X.Y.Z}}"hello"{{end}}`,
+ },
+ {
+ "nested range", "{{range .X}}hello{{range .Y}}goodbye{{end}}{{end}}", noError,
+ `{{range .X}}"hello"{{range .Y}}"goodbye"{{end}}{{end}}`,
+ },
+ {
+ "range with else", "{{range .X}}true{{else}}false{{end}}", noError,
+ `{{range .X}}"true"{{else}}"false"{{end}}`,
+ },
+ {
+ "range over pipeline", "{{range .X|.M}}true{{else}}false{{end}}", noError,
+ `{{range .X | .M}}"true"{{else}}"false"{{end}}`,
+ },
+ {
+ "range []int", "{{range .SI}}{{.}}{{end}}", noError,
+ `{{range .SI}}{{.}}{{end}}`,
+ },
+ {
+ "range 1 var", "{{range $x := .SI}}{{.}}{{end}}", noError,
+ `{{range $x := .SI}}{{.}}{{end}}`,