mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 22:50:35 +03:00
parser/pageparser: Don't store the byte slices
On its own this change doesn't do any magic, but this is part of a bigger picture about making Hugo leaner in the memory usage department.
This commit is contained in:
parent
72b0ccdb01
commit
223bf28004
13 changed files with 385 additions and 198 deletions
|
@ -15,6 +15,8 @@ package pageparser
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -38,27 +40,28 @@ var (
|
|||
tstParamFloat = nti(tScParam, "3.14")
|
||||
tstVal = nti(tScParamVal, "Hello World")
|
||||
tstText = nti(tText, "Hello World")
|
||||
tstIgnoreEscape = nti(TypeIgnore, "\\")
|
||||
)
|
||||
|
||||
var shortCodeLexerTests = []lexerTest{
|
||||
{"empty", "", []Item{tstEOF}},
|
||||
{"spaces", " \t\n", []Item{nti(tText, " \t\n"), tstEOF}},
|
||||
{"text", `to be or not`, []Item{nti(tText, "to be or not"), tstEOF}},
|
||||
{"no markup", `{{< sc1 >}}`, []Item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
{"with EOL", "{{< sc1 \n >}}", []Item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
{"empty", "", []typeText{tstEOF}},
|
||||
{"spaces", " \t\n", []typeText{nti(tText, " \t\n"), tstEOF}},
|
||||
{"text", `to be or not`, []typeText{nti(tText, "to be or not"), tstEOF}},
|
||||
{"no markup", `{{< sc1 >}}`, []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
{"with EOL", "{{< sc1 \n >}}", []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
|
||||
{"forward slash inside name", `{{< sc/sub >}}`, []Item{tstLeftNoMD, tstSCSlash, tstRightNoMD, tstEOF}},
|
||||
{"forward slash inside name", `{{< sc/sub >}}`, []typeText{tstLeftNoMD, tstSCSlash, tstRightNoMD, tstEOF}},
|
||||
|
||||
{"simple with markup", `{{% sc1 %}}`, []Item{tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"with spaces", `{{< sc1 >}}`, []Item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
{"indented on new line", "Hello\n {{% sc1 %}}", []Item{nti(tText, "Hello\n"), nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"indented on new line tab", "Hello\n\t{{% sc1 %}}", []Item{nti(tText, "Hello\n"), nti(tIndentation, "\t"), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"indented on first line", " {{% sc1 %}}", []Item{nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"mismatched rightDelim", `{{< sc1 %}}`, []Item{
|
||||
{"simple with markup", `{{% sc1 %}}`, []typeText{tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"with spaces", `{{< sc1 >}}`, []typeText{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}},
|
||||
{"indented on new line", "Hello\n {{% sc1 %}}", []typeText{nti(tText, "Hello\n"), nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"indented on new line tab", "Hello\n\t{{% sc1 %}}", []typeText{nti(tText, "Hello\n"), nti(tIndentation, "\t"), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"indented on first line", " {{% sc1 %}}", []typeText{nti(tIndentation, " "), tstLeftMD, tstSC1, tstRightMD, tstEOF}},
|
||||
{"mismatched rightDelim", `{{< sc1 %}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1,
|
||||
nti(tError, "unrecognized character in shortcode action: U+0025 '%'. Note: Parameters with non-alphanumeric args must be quoted"),
|
||||
}},
|
||||
{"inner, markup", `{{% sc1 %}} inner {{% /sc1 %}}`, []Item{
|
||||
{"inner, markup", `{{% sc1 %}} inner {{% /sc1 %}}`, []typeText{
|
||||
tstLeftMD,
|
||||
tstSC1,
|
||||
tstRightMD,
|
||||
|
@ -69,79 +72,79 @@ var shortCodeLexerTests = []lexerTest{
|
|||
tstRightMD,
|
||||
tstEOF,
|
||||
}},
|
||||
{"close, but no open", `{{< /sc1 >}}`, []Item{
|
||||
{"close, but no open", `{{< /sc1 >}}`, []typeText{
|
||||
tstLeftNoMD, nti(tError, "got closing shortcode, but none is open"),
|
||||
}},
|
||||
{"close wrong", `{{< sc1 >}}{{< /another >}}`, []Item{
|
||||
{"close wrong", `{{< sc1 >}}{{< /another >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose,
|
||||
nti(tError, "closing tag for shortcode 'another' does not match start tag"),
|
||||
}},
|
||||
{"close, but no open, more", `{{< sc1 >}}{{< /sc1 >}}{{< /another >}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"close with extra keyword", `{{< sc1 >}}{{< /sc1 keyword>}}`, []Item{
|
||||
{"close with extra keyword", `{{< sc1 >}}{{< /sc1 keyword>}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1,
|
||||
nti(tError, "unclosed shortcode"),
|
||||
}},
|
||||
{"float param, positional", `{{< sc1 3.14 >}}`, []Item{
|
||||
{"float param, positional", `{{< sc1 3.14 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "3.14"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"float param, named", `{{< sc1 param1=3.14 >}}`, []Item{
|
||||
{"float param, named", `{{< sc1 param1=3.14 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"named param, raw string", `{{< sc1 param1=` + "`" + "Hello World" + "`" + " >}}", []Item{
|
||||
{"named param, raw string", `{{< sc1 param1=` + "`" + "Hello World" + "`" + " >}}", []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "Hello World"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"float param, named, space before", `{{< sc1 param1= 3.14 >}}`, []Item{
|
||||
{"float param, named, space before", `{{< sc1 param1= 3.14 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"Youtube id", `{{< sc1 -ziL-Q_456igdO-4 >}}`, []Item{
|
||||
{"Youtube id", `{{< sc1 -ziL-Q_456igdO-4 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-Q_456igdO-4"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"non-alphanumerics param quoted", `{{< sc1 "-ziL-.%QigdO-4" >}}`, []Item{
|
||||
{"non-alphanumerics param quoted", `{{< sc1 "-ziL-.%QigdO-4" >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-.%QigdO-4"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"raw string", `{{< sc1` + "`" + "Hello World" + "`" + ` >}}`, []Item{
|
||||
{"raw string", `{{< sc1` + "`" + "Hello World" + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"raw string with newline", `{{< sc1` + "`" + `Hello
|
||||
World` + "`" + ` >}}`, []Item{
|
||||
World` + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, `Hello
|
||||
World`), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"raw string with escape character", `{{< sc1` + "`" + `Hello \b World` + "`" + ` >}}`, []Item{
|
||||
{"raw string with escape character", `{{< sc1` + "`" + `Hello \b World` + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, `Hello \b World`), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"two params", `{{< sc1 param1 param2 >}}`, []Item{
|
||||
{"two params", `{{< sc1 param1 param2 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstParam2, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
// issue #934
|
||||
{"self-closing", `{{< sc1 />}}`, []Item{
|
||||
{"self-closing", `{{< sc1 />}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
// Issue 2498
|
||||
{"multiple self-closing", `{{< sc1 />}}{{< sc1 />}}`, []Item{
|
||||
{"multiple self-closing", `{{< sc1 />}}{{< sc1 />}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD,
|
||||
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"self-closing with param", `{{< sc1 param1 />}}`, []Item{
|
||||
{"self-closing with param", `{{< sc1 param1 />}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []Item{
|
||||
{"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"multiple different self-closing with param", `{{< sc1 param1 />}}{{< sc2 param1 />}}`, []Item{
|
||||
{"multiple different self-closing with param", `{{< sc1 param1 />}}{{< sc2 param1 />}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
|
||||
tstLeftNoMD, tstSC2, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"nested simple", `{{< sc1 >}}{{< sc2 >}}{{< /sc1 >}}`, []Item{
|
||||
{"nested simple", `{{< sc1 >}}{{< sc2 >}}{{< /sc1 >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstRightNoMD,
|
||||
tstLeftNoMD, tstSC2, tstRightNoMD,
|
||||
tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"nested complex", `{{< sc1 >}}ab{{% sc2 param1 %}}cd{{< sc3 >}}ef{{< /sc3 >}}gh{{% /sc2 %}}ij{{< /sc1 >}}kl`, []Item{
|
||||
{"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,
|
||||
|
@ -156,106 +159,109 @@ var shortCodeLexerTests = []lexerTest{
|
|||
nti(tText, "kl"), tstEOF,
|
||||
}},
|
||||
|
||||
{"two quoted params", `{{< sc1 "param nr. 1" "param nr. 2" >}}`, []Item{
|
||||
{"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,
|
||||
}},
|
||||
{"two named params", `{{< sc1 param1="Hello World" param2="p2Val">}}`, []Item{
|
||||
{"two named params", `{{< sc1 param1="Hello World" param2="p2Val">}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstVal, tstParam2, nti(tScParamVal, "p2Val"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"escaped quotes", `{{< sc1 param1=\"Hello World\" >}}`, []Item{
|
||||
{"escaped quotes", `{{< sc1 param1=\"Hello World\" >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstVal, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"escaped quotes, positional param", `{{< sc1 \"param1\" >}}`, []Item{
|
||||
{"escaped quotes, positional param", `{{< sc1 \"param1\" >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"escaped quotes inside escaped quotes", `{{< sc1 param1=\"Hello \"escaped\" World\" >}}`, []Item{
|
||||
{"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`),
|
||||
}},
|
||||
{
|
||||
"escaped quotes inside nonescaped quotes",
|
||||
`{{< sc1 param1="Hello \"escaped\" World" >}}`,
|
||||
[]Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
||||
[]typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstIgnoreEscape, tstIgnoreEscape, nti(tScParamVal, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
||||
},
|
||||
},
|
||||
{
|
||||
"escaped quotes inside nonescaped quotes in positional param",
|
||||
`{{< sc1 "Hello \"escaped\" World" >}}`,
|
||||
[]Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
||||
[]typeText{
|
||||
tstLeftNoMD, tstSC1, tstIgnoreEscape, tstIgnoreEscape, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF,
|
||||
},
|
||||
},
|
||||
{"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{
|
||||
{"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"),
|
||||
}},
|
||||
{"escaped raw string, positional param", `{{< sc1 param1 ` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{
|
||||
{"escaped raw string, positional param", `{{< sc1 param1 ` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"),
|
||||
}},
|
||||
{"two raw string params", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []Item{
|
||||
{"two raw string params", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tScParam, "Second Param"), tstRightNoMD, tstEOF,
|
||||
}},
|
||||
{"unterminated quote", `{{< sc1 param2="Hello World>}}`, []Item{
|
||||
{"unterminated quote", `{{< sc1 param2="Hello World>}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, tstParam2, nti(tError, "unterminated quoted string in shortcode parameter-argument: 'Hello World>}}'"),
|
||||
}},
|
||||
{"unterminated raw string", `{{< sc1` + "`" + "Hello World" + ` >}}`, []Item{
|
||||
{"unterminated raw string", `{{< sc1` + "`" + "Hello World" + ` >}}`, []typeText{
|
||||
tstLeftNoMD, tstSC1, nti(tError, "unterminated raw string in shortcode parameter-argument: 'Hello World >}}'"),
|
||||
}},
|
||||
{"unterminated raw string in second argument", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + ` >}}`, []Item{
|
||||
{"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 >}}'"),
|
||||
}},
|
||||
{"one named param, one not", `{{< sc1 param1="Hello World" p2 >}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"one named param, one quoted positional param, both raw strings", `{{< sc1 param1=` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"one named param, one quoted positional param", `{{< sc1 param1="Hello World" "And Universe" >}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"one quoted positional param, one named param", `{{< sc1 "param1" param2="And Universe" >}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"ono positional param, one not", `{{< sc1 param1 param2="Hello World">}}`, []Item{
|
||||
{"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"),
|
||||
}},
|
||||
{"commented out", `{{</* sc1 */>}}`, []Item{
|
||||
{"commented out", `{{</* sc1 */>}}`, []typeText{
|
||||
nti(tText, "{{<"), nti(tText, " sc1 "), nti(tText, ">}}"), tstEOF,
|
||||
}},
|
||||
{"commented out, with asterisk inside", `{{</* sc1 "**/*.pdf" */>}}`, []Item{
|
||||
{"commented out, with asterisk inside", `{{</* sc1 "**/*.pdf" */>}}`, []typeText{
|
||||
nti(tText, "{{<"), nti(tText, " sc1 \"**/*.pdf\" "), nti(tText, ">}}"), tstEOF,
|
||||
}},
|
||||
{"commented out, missing close", `{{</* sc1 >}}`, []Item{
|
||||
{"commented out, missing close", `{{</* sc1 >}}`, []typeText{
|
||||
nti(tError, "comment must be closed"),
|
||||
}},
|
||||
{"commented out, misplaced close", `{{</* sc1 >}}*/`, []Item{
|
||||
{"commented out, misplaced close", `{{</* sc1 >}}*/`, []typeText{
|
||||
nti(tError, "comment must be closed"),
|
||||
}},
|
||||
// Inline shortcodes
|
||||
{"basic inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}},
|
||||
{"basic inline with space", `{{< sc1.inline >}}Hello World{{< / sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}},
|
||||
{"inline self closing", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD, tstEOF}},
|
||||
{"inline self closing, then a new inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}{{< sc2.inline >}}Hello World{{< /sc2.inline >}}`, []Item{
|
||||
{"basic inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}},
|
||||
{"basic inline with space", `{{< sc1.inline >}}Hello World{{< / sc1.inline >}}`, []typeText{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}},
|
||||
{"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}},
|
||||
{"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,
|
||||
}},
|
||||
{"inline with template syntax", `{{< sc1.inline >}}{{ .Get 0 }}{{ .Get 1 }}{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, nti(tText, "{{ .Get 0 }}"), nti(tText, "{{ .Get 1 }}"), tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}},
|
||||
{"inline with nested shortcode (not supported)", `{{< sc1.inline >}}Hello World{{< sc1 >}}{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, nti(tError, "inline shortcodes do not support nesting")}},
|
||||
{"inline case mismatch", `{{< sc1.Inline >}}Hello World{{< /sc1.Inline >}}`, []Item{tstLeftNoMD, nti(tError, "period in shortcode name only allowed for inline identifiers")}},
|
||||
{"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}},
|
||||
{"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")}},
|
||||
{"inline case mismatch", `{{< sc1.Inline >}}Hello World{{< /sc1.Inline >}}`, []typeText{tstLeftNoMD, nti(tError, "period in shortcode name only allowed for inline identifiers")}},
|
||||
}
|
||||
|
||||
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 := collect([]byte(test.input), true, lexMainSection)
|
||||
if !equal(items, test.items) {
|
||||
t.Errorf("[%d] %s: got\n\t%v\nexpected\n\t%v", i, test.name, items, test.items)
|
||||
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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue