"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tpl/internal/go_templates/texttemplate/parse/parse_test.go" between
hugo-0.80.0.tar.gz and hugo-0.81.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

parse_test.go  (hugo-0.80.0):parse_test.go  (hugo-0.81.0)
skipping to change at line 255 skipping to change at line 255
// Trimming spaces. // Trimming spaces.
{"trim left", "x \r\n\t{{- 3}}", noError, `"x"{{3}}`}, {"trim left", "x \r\n\t{{- 3}}", noError, `"x"{{3}}`},
{"trim right", "{{3 -}}\n\n\ty", noError, `{{3}}"y"`}, {"trim right", "{{3 -}}\n\n\ty", noError, `{{3}}"y"`},
{"trim left and right", "x \r\n\t{{- 3 -}}\n\n\ty", noError, `"x"{{3}}"y" `}, {"trim left and right", "x \r\n\t{{- 3 -}}\n\n\ty", noError, `"x"{{3}}"y" `},
{"trim with extra spaces", "x\n{{- 3 -}}\ny", noError, `"x"{{3}}"y"`}, {"trim with extra spaces", "x\n{{- 3 -}}\ny", noError, `"x"{{3}}"y"`},
{"comment trim left", "x \r\n\t{{- /* hi */}}", noError, `"x"`}, {"comment trim left", "x \r\n\t{{- /* hi */}}", noError, `"x"`},
{"comment trim right", "{{/* hi */ -}}\n\n\ty", noError, `"y"`}, {"comment trim right", "{{/* hi */ -}}\n\n\ty", noError, `"y"`},
{"comment trim left and right", "x \r\n\t{{- /* */ -}}\n\n\ty", noError, `"x""y"`}, {"comment trim left and right", "x \r\n\t{{- /* */ -}}\n\n\ty", noError, `"x""y"`},
{"block definition", `{{block "foo" .}}hello{{end}}`, noError, {"block definition", `{{block "foo" .}}hello{{end}}`, noError,
`{{template "foo" .}}`}, `{{template "foo" .}}`},
{"newline in assignment", "{{ $x \n := \n 1 \n }}", noError, "{{$x := 1}}
"},
{"newline in empty action", "{{\n}}", hasError, "{{\n}}"},
{"newline in pipeline", "{{\n\"x\"\n|\nprintf\n}}", noError, `{{"x" | pri
ntf}}`},
{"newline in comment", "{{/*\nhello\n*/}}", noError, ""},
{"newline in comment", "{{-\n/*\nhello\n*/\n-}}", noError, ""},
// Errors. // Errors.
{"unclosed action", "hello{{range", hasError, ""}, {"unclosed action", "hello{{range", hasError, ""},
{"unmatched end", "{{end}}", hasError, ""}, {"unmatched end", "{{end}}", hasError, ""},
{"unmatched else", "{{else}}", hasError, ""}, {"unmatched else", "{{else}}", hasError, ""},
{"unmatched else after if", "{{if .X}}hello{{end}}{{else}}", hasError, "" }, {"unmatched else after if", "{{if .X}}hello{{end}}{{else}}", hasError, "" },
{"multiple else", "{{if .X}}1{{else}}2{{else}}3{{end}}", hasError, ""}, {"multiple else", "{{if .X}}1{{else}}2{{else}}3{{end}}", hasError, ""},
{"missing end", "hello{{range .x}}", hasError, ""}, {"missing end", "hello{{range .x}}", hasError, ""},
{"missing end after else", "hello{{range .x}}{{else}}", hasError, ""}, {"missing end after else", "hello{{range .x}}{{else}}", hasError, ""},
{"undefined function", "hello{{undefined}}", hasError, ""}, {"undefined function", "hello{{undefined}}", hasError, ""},
{"undefined variable", "{{$x}}", hasError, ""}, {"undefined variable", "{{$x}}", hasError, ""},
skipping to change at line 353 skipping to change at line 360
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
testParse(false, t) testParse(false, t)
} }
// Same as TestParse, but we copy the node first // Same as TestParse, but we copy the node first
func TestParseCopy(t *testing.T) { func TestParseCopy(t *testing.T) {
testParse(true, t) testParse(true, t)
} }
func TestParseWithComments(t *testing.T) {
textFormat = "%q"
defer func() { textFormat = "%s" }()
tests := [...]parseTest{
{"comment", "{{/*\n\n\n*/}}", noError, "{{/*\n\n\n*/}}"},
{"comment trim left", "x \r\n\t{{- /* hi */}}", noError, `"x"{{/*
hi */}}`},
{"comment trim right", "{{/* hi */ -}}\n\n\ty", noError, `{{/* hi
*/}}"y"`},
{"comment trim left and right", "x \r\n\t{{- /* */ -}}\n\n\ty", n
oError, `"x"{{/* */}}"y"`},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tr := New(test.name)
tr.Mode = ParseComments
tmpl, err := tr.Parse(test.input, "", "", make(map[string
]*Tree))
if err != nil {
t.Errorf("%q: expected error; got none", test.nam
e)
}
if result := tmpl.Root.String(); result != test.result {
t.Errorf("%s=(%q): got\n\t%v\nexpected\n\t%v", te
st.name, test.input, result, test.result)
}
})
}
}
type isEmptyTest struct { type isEmptyTest struct {
name string name string
input string input string
empty bool empty bool
} }
var isEmptyTests = []isEmptyTest{ var isEmptyTests = []isEmptyTest{
{"empty", ``, true}, {"empty", ``, true},
{"nonempty", `hello`, false}, {"nonempty", `hello`, false},
{"spaces only", " \t\n \t\n", true}, {"spaces only", " \t\n \t\n", true},
{"comment only", "{{/* comment */}}", true},
{"definition", `{{define "x"}}something{{end}}`, true}, {"definition", `{{define "x"}}something{{end}}`, true},
{"definitions and space", "{{define `x`}}something{{end}}\n\n{{define `y` }}something{{end}}\n\n", true}, {"definitions and space", "{{define `x`}}something{{end}}\n\n{{define `y` }}something{{end}}\n\n", true},
{"definitions and text", "{{define `x`}}something{{end}}\nx\n{{define `y` }}something{{end}}\ny\n", false}, {"definitions and text", "{{define `x`}}something{{end}}\nx\n{{define `y` }}something{{end}}\ny\n", false},
{"definition and action", "{{define `x`}}something{{end}}{{if 3}}foo{{end }}", false}, {"definition and action", "{{define `x`}}something{{end}}{{if 3}}foo{{end }}", false},
} }
func TestIsEmpty(t *testing.T) { func TestIsEmpty(t *testing.T) {
if !IsEmptyTree(nil) { if !IsEmptyTree(nil) {
t.Errorf("nil tree is not empty") t.Errorf("nil tree is not empty")
} }
skipping to change at line 406 skipping to change at line 438
if wantContext != gotContext { if wantContext != gotContext {
t.Errorf("wrong error location want %q got %q", wantContext, gotC ontext) t.Errorf("wrong error location want %q got %q", wantContext, gotC ontext)
} }
} }
// All failures, and the result is a string that must appear in the error messag e. // All failures, and the result is a string that must appear in the error messag e.
var errorTests = []parseTest{ var errorTests = []parseTest{
// Check line numbers are accurate. // Check line numbers are accurate.
{"unclosed1", {"unclosed1",
"line1\n{{", "line1\n{{",
hasError, `unclosed1:2: unexpected unclosed action in command`}, hasError, `unclosed1:2: unclosed action`},
{"unclosed2", {"unclosed2",
"line1\n{{define `x`}}line2\n{{", "line1\n{{define `x`}}line2\n{{",
hasError, `unclosed2:3: unexpected unclosed action in command`}, hasError, `unclosed2:3: unclosed action`},
{"unclosed3",
"line1\n{{\"x\"\n\"y\"\n",
hasError, `unclosed3:4: unclosed action started at unclosed3:2`},
{"unclosed4",
"{{\n\n\n\n\n",
hasError, `unclosed4:6: unclosed action started at unclosed4:1`},
{"var1",
"line1\n{{\nx\n}}",
hasError, `var1:3: function "x" not defined`},
// Specific errors. // Specific errors.
{"function", {"function",
"{{foo}}", "{{foo}}",
hasError, `function "foo" not defined`}, hasError, `function "foo" not defined`},
{"comment", {"comment1",
"{{/*}}", "{{/*}}",
hasError, `unclosed comment`}, hasError, `comment1:1: unclosed comment`},
{"comment2",
"{{/*\nhello\n}}",
hasError, `comment2:1: unclosed comment`},
{"lparen", {"lparen",
"{{.X (1 2 3}}", "{{.X (1 2 3}}",
hasError, `unclosed left paren`}, hasError, `unclosed left paren`},
{"rparen", {"rparen",
"{{.X 1 2 3)}}", "{{.X 1 2 3 ) }}",
hasError, `unexpected ")"`}, hasError, `unexpected ")" in command`},
{"rparen2",
"{{(.X 1 2 3",
hasError, `unclosed action`},
{"space", {"space",
"{{`x`3}}", "{{`x`3}}",
hasError, `in operand`}, hasError, `in operand`},
{"idchar", {"idchar",
"{{a#}}", "{{a#}}",
hasError, `'#'`}, hasError, `'#'`},
{"charconst", {"charconst",
"{{'a}}", "{{'a}}",
hasError, `unterminated character constant`}, hasError, `unterminated character constant`},
{"stringconst", {"stringconst",
skipping to change at line 468 skipping to change at line 515
"{{true.any}}", "{{true.any}}",
hasError, `unexpected . after term`}, hasError, `unexpected . after term`},
{"wrongpipeline", {"wrongpipeline",
"{{12|false}}", "{{12|false}}",
hasError, `non executable command in pipeline`}, hasError, `non executable command in pipeline`},
{"emptypipeline", {"emptypipeline",
`{{ ( ) }}`, `{{ ( ) }}`,
hasError, `missing value for parenthesized pipeline`}, hasError, `missing value for parenthesized pipeline`},
{"multilinerawstring", {"multilinerawstring",
"{{ $v := `\n` }} {{", "{{ $v := `\n` }} {{",
hasError, `multilinerawstring:2: unexpected unclosed action`}, hasError, `multilinerawstring:2: unclosed action`},
{"rangeundefvar", {"rangeundefvar",
"{{range $k}}{{end}}", "{{range $k}}{{end}}",
hasError, `undefined variable`}, hasError, `undefined variable`},
{"rangeundefvars", {"rangeundefvars",
"{{range $k, $v}}{{end}}", "{{range $k, $v}}{{end}}",
hasError, `undefined variable`}, hasError, `undefined variable`},
{"rangemissingvalue1", {"rangemissingvalue1",
"{{range $k,}}{{end}}", "{{range $k,}}{{end}}",
hasError, `missing value for range`}, hasError, `missing value for range`},
{"rangemissingvalue2", {"rangemissingvalue2",
 End of changes. 9 change blocks. 
7 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)