mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-30 01:23:34 -05:00
Add benchmark for the shortcode lexer
This commit is contained in:
parent
ecb2aca6a2
commit
8557e2cbb8
1 changed files with 13 additions and 1 deletions
|
@ -126,7 +126,7 @@ var shortCodeLexerTests = []shortCodeLexerTest{
|
||||||
item{tText, 0, "{{<"}, item{tText, 0, " sc1 >}}"}, {tError, 0, "comment ends before the right shortcode delimiter"}}},
|
item{tText, 0, "{{<"}, item{tText, 0, " sc1 >}}"}, {tError, 0, "comment ends before the right shortcode delimiter"}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPagelexer(t *testing.T) {
|
func TestShortcodeLexer(t *testing.T) {
|
||||||
for _, test := range shortCodeLexerTests {
|
for _, test := range shortCodeLexerTests {
|
||||||
|
|
||||||
items := collect(&test)
|
items := collect(&test)
|
||||||
|
@ -136,6 +136,18 @@ func TestPagelexer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkShortcodeLexer(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
for _, test := range shortCodeLexerTests {
|
||||||
|
items := collect(&test)
|
||||||
|
if !equal(items, test.items) {
|
||||||
|
b.Errorf("%s: got\n\t%v\nexpected\n\t%v", test.name, items, test.items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func collect(t *shortCodeLexerTest) (items []item) {
|
func collect(t *shortCodeLexerTest) (items []item) {
|
||||||
l := newShortcodeLexer(t.name, t.input, 0)
|
l := newShortcodeLexer(t.name, t.input, 0)
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in a new issue