"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tpl/internal/go_templates/texttemplate/parse/lex_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).

lex_test.go  (hugo-0.80.0):lex_test.go  (hugo-0.81.0)
skipping to change at line 20 skipping to change at line 20
"fmt" "fmt"
"testing" "testing"
) )
// Make the types prettyprint. // Make the types prettyprint.
var itemName = map[itemType]string{ var itemName = map[itemType]string{
itemError: "error", itemError: "error",
itemBool: "bool", itemBool: "bool",
itemChar: "char", itemChar: "char",
itemCharConstant: "charconst", itemCharConstant: "charconst",
itemComment: "comment",
itemComplex: "complex", itemComplex: "complex",
itemDeclare: ":=", itemDeclare: ":=",
itemEOF: "EOF", itemEOF: "EOF",
itemField: "field", itemField: "field",
itemIdentifier: "identifier", itemIdentifier: "identifier",
itemLeftDelim: "left delim", itemLeftDelim: "left delim",
itemLeftParen: "(", itemLeftParen: "(",
itemNumber: "number", itemNumber: "number",
itemPipe: "pipe", itemPipe: "pipe",
itemRawString: "raw string", itemRawString: "raw string",
skipping to change at line 95 skipping to change at line 96
tRawQuote = mkItem(itemRawString, raw) tRawQuote = mkItem(itemRawString, raw)
tRawQuoteNL = mkItem(itemRawString, rawNL) tRawQuoteNL = mkItem(itemRawString, rawNL)
) )
var lexTests = []lexTest{ var lexTests = []lexTest{
{"empty", "", []item{tEOF}}, {"empty", "", []item{tEOF}},
{"spaces", " \t\n", []item{mkItem(itemText, " \t\n"), tEOF}}, {"spaces", " \t\n", []item{mkItem(itemText, " \t\n"), tEOF}},
{"text", `now is the time`, []item{mkItem(itemText, "now is the time"), t EOF}}, {"text", `now is the time`, []item{mkItem(itemText, "now is the time"), t EOF}},
{"text with comment", "hello-{{/* this is a comment */}}-world", []item{ {"text with comment", "hello-{{/* this is a comment */}}-world", []item{
mkItem(itemText, "hello-"), mkItem(itemText, "hello-"),
mkItem(itemComment, "/* this is a comment */"),
mkItem(itemText, "-world"), mkItem(itemText, "-world"),
tEOF, tEOF,
}}, }},
{"punctuation", "{{,@% }}", []item{ {"punctuation", "{{,@% }}", []item{
tLeft, tLeft,
mkItem(itemChar, ","), mkItem(itemChar, ","),
mkItem(itemChar, "@"), mkItem(itemChar, "@"),
mkItem(itemChar, "%"), mkItem(itemChar, "%"),
tSpace, tSpace,
tRight, tRight,
skipping to change at line 316 skipping to change at line 318
{"trimming spaces before and after", "hello- {{- 3 -}} -world", []item{ {"trimming spaces before and after", "hello- {{- 3 -}} -world", []item{
mkItem(itemText, "hello-"), mkItem(itemText, "hello-"),
tLeft, tLeft,
mkItem(itemNumber, "3"), mkItem(itemNumber, "3"),
tRight, tRight,
mkItem(itemText, "-world"), mkItem(itemText, "-world"),
tEOF, tEOF,
}}, }},
{"trimming spaces before and after comment", "hello- {{- /* hello */ -}} -world", []item{ {"trimming spaces before and after comment", "hello- {{- /* hello */ -}} -world", []item{
mkItem(itemText, "hello-"), mkItem(itemText, "hello-"),
mkItem(itemComment, "/* hello */"),
mkItem(itemText, "-world"), mkItem(itemText, "-world"),
tEOF, tEOF,
}}, }},
// errors // errors
{"badchar", "#{{\x01}}", []item{ {"badchar", "#{{\x01}}", []item{
mkItem(itemText, "#"), mkItem(itemText, "#"),
tLeft, tLeft,
mkItem(itemError, "unrecognized character in action: U+0001"), mkItem(itemError, "unrecognized character in action: U+0001"),
}}, }},
{"unclosed action", "{{\n}}", []item{ {"unclosed action", "{{", []item{
tLeft, tLeft,
mkItem(itemError, "unclosed action"), mkItem(itemError, "unclosed action"),
}}, }},
{"EOF in action", "{{range", []item{ {"EOF in action", "{{range", []item{
tLeft, tLeft,
tRange, tRange,
mkItem(itemError, "unclosed action"), mkItem(itemError, "unclosed action"),
}}, }},
{"unclosed quote", "{{\"\n\"}}", []item{ {"unclosed quote", "{{\"\n\"}}", []item{
tLeft, tLeft,
skipping to change at line 394 skipping to change at line 397
// This one is an error that we can't catch because it breaks templates w ith // This one is an error that we can't catch because it breaks templates w ith
// minimized JavaScript. Should have fixed it before Go 1.1. // minimized JavaScript. Should have fixed it before Go 1.1.
{"unmatched right delimiter", "hello-{.}}-world", []item{ {"unmatched right delimiter", "hello-{.}}-world", []item{
mkItem(itemText, "hello-{.}}-world"), mkItem(itemText, "hello-{.}}-world"),
tEOF, tEOF,
}}, }},
} }
// collect gathers the emitted items into a slice. // collect gathers the emitted items into a slice.
func collect(t *lexTest, left, right string) (items []item) { func collect(t *lexTest, left, right string) (items []item) {
l := lex(t.name, t.input, left, right) l := lex(t.name, t.input, left, right, true)
for { for {
item := l.nextItem() item := l.nextItem()
items = append(items, item) items = append(items, item)
if item.typ == itemEOF || item.typ == itemError { if item.typ == itemEOF || item.typ == itemError {
break break
} }
} }
return return
} }
skipping to change at line 534 skipping to change at line 537
} }
} }
} }
} }
} }
// Test that an error shuts down the lexing goroutine. // Test that an error shuts down the lexing goroutine.
func TestShutdown(t *testing.T) { func TestShutdown(t *testing.T) {
// We need to duplicate template.Parse here to hold on to the lexer. // We need to duplicate template.Parse here to hold on to the lexer.
const text = "erroneous{{define}}{{else}}1234" const text = "erroneous{{define}}{{else}}1234"
lexer := lex("foo", text, "{{", "}}") lexer := lex("foo", text, "{{", "}}", false)
_, err := New("root").parseLexer(lexer) _, err := New("root").parseLexer(lexer)
if err == nil { if err == nil {
t.Fatalf("expected error") t.Fatalf("expected error")
} }
// The error should have drained the input. Therefore, the lexer should b e shut down. // The error should have drained the input. Therefore, the lexer should b e shut down.
token, ok := <-lexer.items token, ok := <-lexer.items
if ok { if ok {
t.Fatalf("input was not drained; got %v", token) t.Fatalf("input was not drained; got %v", token)
} }
} }
 End of changes. 6 change blocks. 
3 lines changed or deleted 6 lines changed or added

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