mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
7285e74090
There are some breaking changes in this commit, see #11455. Closes #11455 Closes #11549 This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build. The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate. A list of the notable new features: * A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server. * A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently. * You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs. We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections). Memory Limit * Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory. New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively. This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive): Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers. Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds. Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role). Fixes #10169 Fixes #10364 Fixes #10482 Fixes #10630 Fixes #10656 Fixes #10694 Fixes #10918 Fixes #11262 Fixes #11439 Fixes #11453 Fixes #11457 Fixes #11466 Fixes #11540 Fixes #11551 Fixes #11556 Fixes #11654 Fixes #11661 Fixes #11663 Fixes #11664 Fixes #11669 Fixes #11671 Fixes #11807 Fixes #11808 Fixes #11809 Fixes #11815 Fixes #11840 Fixes #11853 Fixes #11860 Fixes #11883 Fixes #11904 Fixes #7388 Fixes #7425 Fixes #7436 Fixes #7544 Fixes #7882 Fixes #7960 Fixes #8255 Fixes #8307 Fixes #8863 Fixes #8927 Fixes #9192 Fixes #9324
284 lines
14 KiB
Go
284 lines
14 KiB
Go
// Copyright 2018 The Hugo Authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package pageparser
|
|
|
|
import (
|
|
"testing"
|
|
|
|
qt "github.com/frankban/quicktest"
|
|
)
|
|
|
|
var (
|
|
tstEOF = nti(tEOF, "")
|
|
tstLeftNoMD = nti(tLeftDelimScNoMarkup, "{{<")
|
|
tstRightNoMD = nti(tRightDelimScNoMarkup, ">}}")
|
|
tstLeftMD = nti(tLeftDelimScWithMarkup, "{{%")
|
|
tstRightMD = nti(tRightDelimScWithMarkup, "%}}")
|
|
tstSCClose = nti(tScClose, "/")
|
|
tstSC1 = nti(tScName, "sc1")
|
|
tstSC1Inline = nti(tScNameInline, "sc1.inline")
|
|
tstSC2Inline = nti(tScNameInline, "sc2.inline")
|
|
tstSC2 = nti(tScName, "sc2")
|
|
tstSC3 = nti(tScName, "sc3")
|
|
tstSCSlash = nti(tScName, "sc/sub")
|
|
tstParam1 = nti(tScParam, "param1")
|
|
tstParam2 = nti(tScParam, "param2")
|
|
tstVal = nti(tScParamVal, "Hello World")
|
|
tstText = nti(tText, "Hello World")
|
|
)
|
|
|
|
var shortCodeLexerTests = []lexerTest{
|
|
{"empty", "", []typeText{tstEOF}, nil},
|
|
{"spaces", " \t\n", []typeText{nti(tText, " \t\n"), tstEOF}, nil},
|
|
{"text", `to be or not`, []typeText{nti(tText, "to be or not"), tstEOF}, nil},
|
|
{"no markup", `{{< sc1 >}}`, []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}, nil},
|
|
{"with EOL", "{{< sc1 \n >}}", []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}, nil},
|
|
|
|
{"forward slash inside name", `{{< sc/sub >}}`, []typeText{tstLeftNoMD, tstSCSlash, tstRightNoMD, tstEOF}, nil},
|
|
|
|
{"simple with markup", `{{% sc1 %}}`, []typeText{tstLeftMD, tstSC1, tstRightMD, tstEOF}, nil},
|
|
{"with spaces", `{{< sc1 >}}`, []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}, nil},
|
|
{"indented on new line", "Hello\n {{% sc1 %}}", []typeText{nti(tText, "Hello\n"), nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}, nil},
|
|
{"indented on new line tab", "Hello\n\t{{% sc1 %}}", []typeText{nti(tText, "Hello\n"), nti(tIndentation, "\t"), tstLeftMD, tstSC1, tstRightMD, tstEOF}, nil},
|
|
{"indented on first line", " {{% sc1 %}}", []typeText{nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}, nil},
|
|
{"mismatched rightDelim", `{{< sc1 %}}`, []typeText{
|
|
tstLeftNoMD, tstSC1,
|
|
nti(tError, "unrecognized character in shortcode action: U+0025 '%'. Note: Parameters with non-alphanumeric args must be quoted"),
|
|
}, nil},
|
|
{"inner, markup", `{{% sc1 %}} inner {{% /sc1 %}}`, []typeText{
|
|
tstLeftMD,
|
|
tstSC1,
|
|
tstRightMD,
|
|
nti(tText, " inner "),
|
|
tstLeftMD,
|
|
tstSCClose,
|
|
tstSC1,
|
|
tstRightMD,
|
|
tstEOF,
|
|
}, nil},
|
|
{"close, but no open", `{{< /sc1 >}}`, []typeText{
|
|
tstLeftNoMD, nti(tError, "got closing shortcode, but none is open"),
|
|
}, nil},
|
|
{"close wrong", `{{< sc1 >}}{{< /another >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose,
|
|
nti(tError, "closing tag for shortcode 'another' does not match start tag"),
|
|
}, nil},
|
|
{"close, but no open, more", `{{< sc1 >}}{{< /sc1 >}}{{< /another >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose,
|
|
nti(tError, "closing tag for shortcode 'another' does not match start tag"),
|
|
}, nil},
|
|
{"close with extra keyword", `{{< sc1 >}}{{< /sc1 keyword>}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1,
|
|
nti(tError, "unclosed shortcode"),
|
|
}, nil},
|
|
{"float param, positional", `{{< sc1 3.14 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "3.14"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"float param, named", `{{< sc1 param1=3.14 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"named param, raw string", `{{< sc1 param1=` + "`" + "Hello World" + "`" + " >}}", []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "Hello World"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"float param, named, space before", `{{< sc1 param1= 3.14 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"Youtube id", `{{< sc1 -ziL-Q_456igdO-4 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-Q_456igdO-4"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"non-alphanumerics param quoted", `{{< sc1 "-ziL-.%QigdO-4" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-.%QigdO-4"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"raw string", `{{< sc1` + "`" + "Hello World" + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"raw string with newline", `{{< sc1` + "`" + `Hello
|
|
World` + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, `Hello
|
|
World`), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"raw string with escape character", `{{< sc1` + "`" + `Hello \b World` + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, `Hello \b World`), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"two params", `{{< sc1 param1 param2 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstParam2, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
// issue #934
|
|
{"self-closing", `{{< sc1 />}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
// Issue 2498
|
|
{"multiple self-closing", `{{< sc1 />}}{{< sc1 />}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD,
|
|
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"self-closing with param", `{{< sc1 param1 />}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
|
|
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"multiple different self-closing with param", `{{< sc1 param1 />}}{{< sc2 param1 />}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
|
|
tstLeftNoMD, tstSC2, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"nested simple", `{{< sc1 >}}{{< sc2 >}}{{< /sc1 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstRightNoMD,
|
|
tstLeftNoMD, tstSC2, tstRightNoMD,
|
|
tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"nested complex", `{{< sc1 >}}ab{{% sc2 param1 %}}cd{{< sc3 >}}ef{{< /sc3 >}}gh{{% /sc2 %}}ij{{< /sc1 >}}kl`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstRightNoMD,
|
|
nti(tText, "ab"),
|
|
tstLeftMD, tstSC2, tstParam1, tstRightMD,
|
|
nti(tText, "cd"),
|
|
tstLeftNoMD, tstSC3, tstRightNoMD,
|
|
nti(tText, "ef"),
|
|
tstLeftNoMD, tstSCClose, tstSC3, tstRightNoMD,
|
|
nti(tText, "gh"),
|
|
tstLeftMD, tstSCClose, tstSC2, tstRightMD,
|
|
nti(tText, "ij"),
|
|
tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD,
|
|
nti(tText, "kl"), tstEOF,
|
|
}, nil},
|
|
|
|
{"two quoted params", `{{< sc1 "param nr. 1" "param nr. 2" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "param nr. 1"), nti(tScParam, "param nr. 2"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"two named params", `{{< sc1 param1="Hello World" param2="p2Val">}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstVal, tstParam2, nti(tScParamVal, "p2Val"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"escaped quotes", `{{< sc1 param1=\"Hello World\" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstVal, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"escaped quotes, positional param", `{{< sc1 \"param1\" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"escaped quotes inside escaped quotes", `{{< sc1 param1=\"Hello \"escaped\" World\" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1,
|
|
nti(tScParamVal, `Hello `), nti(tError, `got positional parameter 'escaped'. Cannot mix named and positional parameters`),
|
|
}, nil},
|
|
{
|
|
"escaped quotes inside nonescaped quotes",
|
|
`{{< sc1 param1="Hello \"escaped\" World" >}}`,
|
|
[]typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
|
},
|
|
nil,
|
|
},
|
|
{
|
|
"escaped quotes inside nonescaped quotes in positional param",
|
|
`{{< sc1 "Hello \"escaped\" World" >}}`,
|
|
[]typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
|
},
|
|
nil,
|
|
},
|
|
{"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"),
|
|
}, nil},
|
|
{"escaped raw string, positional param", `{{< sc1 param1 ` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"),
|
|
}, nil},
|
|
{"two raw string params", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tScParam, "Second Param"), tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"unterminated quote", `{{< sc1 param2="Hello World>}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam2, nti(tError, "unterminated quoted string in shortcode parameter-argument: 'Hello World>}}'"),
|
|
}, nil},
|
|
{"unterminated raw string", `{{< sc1` + "`" + "Hello World" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tError, "unterminated raw string in shortcode parameter-argument: 'Hello World >}}'"),
|
|
}, nil},
|
|
{"unterminated raw string in second argument", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tError, "unterminated raw string in shortcode parameter-argument: 'Second Param >}}'"),
|
|
}, nil},
|
|
{"one named param, one not", `{{< sc1 param1="Hello World" p2 >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
|
nti(tError, "got positional parameter 'p2'. Cannot mix named and positional parameters"),
|
|
}, nil},
|
|
{"one named param, one quoted positional param, both raw strings", `{{< sc1 param1=` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
|
nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters"),
|
|
}, nil},
|
|
{"one named param, one quoted positional param", `{{< sc1 param1="Hello World" "And Universe" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
|
nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters"),
|
|
}, nil},
|
|
{"one quoted positional param, one named param", `{{< sc1 "param1" param2="And Universe" >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1,
|
|
nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters"),
|
|
}, nil},
|
|
{"ono positional param, one not", `{{< sc1 param1 param2="Hello World">}}`, []typeText{
|
|
tstLeftNoMD, tstSC1, tstParam1,
|
|
nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters"),
|
|
}, nil},
|
|
{"commented out", `{{</* sc1 */>}}`, []typeText{
|
|
nti(tText, "{{<"), nti(tText, " sc1 "), nti(tText, ">}}"), tstEOF,
|
|
}, nil},
|
|
{"commented out, with asterisk inside", `{{</* sc1 "**/*.pdf" */>}}`, []typeText{
|
|
nti(tText, "{{<"), nti(tText, " sc1 \"**/*.pdf\" "), nti(tText, ">}}"), tstEOF,
|
|
}, nil},
|
|
{"commented out, missing close", `{{</* sc1 >}}`, []typeText{
|
|
nti(tError, "comment must be closed"),
|
|
}, nil},
|
|
{"commented out, misplaced close", `{{</* sc1 >}}*/`, []typeText{
|
|
nti(tError, "comment must be closed"),
|
|
}, nil},
|
|
// Inline shortcodes
|
|
{"basic inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}, nil},
|
|
{"basic inline with space", `{{< sc1.inline >}}Hello World{{< / sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}, nil},
|
|
{"inline self closing", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD, tstEOF}, nil},
|
|
{"inline self closing, then a new inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}{{< sc2.inline >}}Hello World{{< /sc2.inline >}}`, []typeText{
|
|
tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD,
|
|
tstLeftNoMD, tstSC2Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC2Inline, tstRightNoMD, tstEOF,
|
|
}, nil},
|
|
{"inline with template syntax", `{{< sc1.inline >}}{{ .Get 0 }}{{ .Get 1 }}{{< /sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, nti(tText, "{{ .Get 0 }}"), nti(tText, "{{ .Get 1 }}"), tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}, nil},
|
|
{"inline with nested shortcode (not supported)", `{{< sc1.inline >}}Hello World{{< sc1 >}}{{< /sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, nti(tError, "inline shortcodes do not support nesting")}, nil},
|
|
{"inline case mismatch", `{{< sc1.Inline >}}Hello World{{< /sc1.Inline >}}`, []typeText{tstLeftNoMD, nti(tError, "period in shortcode name only allowed for inline identifiers")}, nil},
|
|
}
|
|
|
|
func TestShortcodeLexer(t *testing.T) {
|
|
t.Parallel()
|
|
c := qt.New(t)
|
|
for i, test := range shortCodeLexerTests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
items, err := collect([]byte(test.input), true, lexMainSection)
|
|
c.Assert(err, qt.IsNil)
|
|
if !equal(test.input, items, test.items) {
|
|
got := itemsToString(items, []byte(test.input))
|
|
expected := testItemsToString(test.items)
|
|
c.Assert(got, qt.Equals, expected, qt.Commentf("Test %d: %s", i, test.name))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkShortcodeLexer(b *testing.B) {
|
|
testInputs := make([][]byte, len(shortCodeLexerTests))
|
|
for i, input := range shortCodeLexerTests {
|
|
testInputs[i] = []byte(input.input)
|
|
}
|
|
var cfg Config
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
for _, input := range testInputs {
|
|
_, err := collectWithConfig(input, true, lexMainSection, cfg)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|