diff options
Diffstat (limited to 'parser')
-rw-r--r-- | parser/lowercase_camel_json.go | 7 | ||||
-rw-r--r-- | parser/metadecoders/decoder.go | 5 | ||||
-rw-r--r-- | parser/metadecoders/decoder_test.go | 1 | ||||
-rw-r--r-- | parser/metadecoders/format.go | 2 | ||||
-rw-r--r-- | parser/pageparser/item_test.go | 1 | ||||
-rw-r--r-- | parser/pageparser/pagelexer.go | 7 | ||||
-rw-r--r-- | parser/pageparser/pagelexer_intro.go | 2 | ||||
-rw-r--r-- | parser/pageparser/pagelexer_shortcode.go | 3 | ||||
-rw-r--r-- | parser/pageparser/pagelexer_test.go | 1 | ||||
-rw-r--r-- | parser/pageparser/pageparser.go | 1 | ||||
-rw-r--r-- | parser/pageparser/pageparser_intro_test.go | 1 | ||||
-rw-r--r-- | parser/pageparser/pageparser_main_test.go | 2 | ||||
-rw-r--r-- | parser/pageparser/pageparser_shortcode_test.go | 149 |
13 files changed, 105 insertions, 77 deletions
diff --git a/parser/lowercase_camel_json.go b/parser/lowercase_camel_json.go index 6994d1215..fb283a1c4 100644 --- a/parser/lowercase_camel_json.go +++ b/parser/lowercase_camel_json.go @@ -22,8 +22,10 @@ import ( ) // Regexp definitions -var keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`) -var wordBarrierRegex = regexp.MustCompile(`(\w)([A-Z])`) +var ( + keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`) + wordBarrierRegex = regexp.MustCompile(`(\w)([A-Z])`) +) // Code adapted from https://gist.github.com/piersy/b9934790a8892db1a603820c0c23e4a7 type LowerCaseCamelJSONMarshaller struct { @@ -36,7 +38,6 @@ func (c LowerCaseCamelJSONMarshaller) MarshalJSON() ([]byte, error) { converted := keyMatchRegex.ReplaceAllFunc( marshalled, func(match []byte) []byte { - // Attributes on the form XML, JSON etc. if bytes.Equal(match, bytes.ToUpper(match)) { return bytes.ToLower(match) diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go index 2624ad16f..7fc8330af 100644 --- a/parser/metadecoders/decoder.go +++ b/parser/metadecoders/decoder.go @@ -119,7 +119,6 @@ func (d Decoder) Unmarshal(data []byte, f Format) (interface{}, error) { default: return make(map[string]interface{}), nil } - } var v interface{} err := d.UnmarshalTo(data, f, &v) @@ -129,7 +128,6 @@ func (d Decoder) Unmarshal(data []byte, f Format) (interface{}, error) { // UnmarshalTo unmarshals data in format f into v. func (d Decoder) UnmarshalTo(data []byte, f Format, v interface{}) error { - var err error switch f { @@ -181,7 +179,6 @@ func (d Decoder) UnmarshalTo(data []byte, f Format, v interface{}) error { } return toFileError(f, errors.Wrap(err, "unmarshal failed")) - } func (d Decoder) unmarshalCSV(data []byte, v interface{}) error { @@ -203,7 +200,6 @@ func (d Decoder) unmarshalCSV(data []byte, v interface{}) error { } return nil - } func parseORGDate(s string) string { @@ -255,7 +251,6 @@ func toFileError(f Format, err error) error { // // Inspired by https://github.com/stripe/stripe-mock, MIT licensed func stringifyMapKeys(in interface{}) (interface{}, bool) { - switch in := in.(type) { case []interface{}: for i, v := range in { diff --git a/parser/metadecoders/decoder_test.go b/parser/metadecoders/decoder_test.go index d11d578ba..e0990a5f7 100644 --- a/parser/metadecoders/decoder_test.go +++ b/parser/metadecoders/decoder_test.go @@ -87,7 +87,6 @@ func TestUnmarshalToInterface(t *testing.T) { } } - } func TestUnmarshalStringTo(t *testing.T) { diff --git a/parser/metadecoders/format.go b/parser/metadecoders/format.go index 9e9cc2e1f..d2b35223d 100644 --- a/parser/metadecoders/format.go +++ b/parser/metadecoders/format.go @@ -39,7 +39,6 @@ func FormatFromString(formatStr string) Format { if strings.Contains(formatStr, ".") { // Assume a filename formatStr = strings.TrimPrefix(filepath.Ext(formatStr), ".") - } switch formatStr { case "yaml", "yml": @@ -55,7 +54,6 @@ func FormatFromString(formatStr string) Format { } return "" - } // FormatFromMediaType gets the Format given a MIME type, empty string diff --git a/parser/pageparser/item_test.go b/parser/pageparser/item_test.go index a30860f17..cd01202c6 100644 --- a/parser/pageparser/item_test.go +++ b/parser/pageparser/item_test.go @@ -31,5 +31,4 @@ func TestItemValTyped(t *testing.T) { c.Assert(Item{Val: []byte("true")}.ValTyped(), qt.Equals, true) c.Assert(Item{Val: []byte("false")}.ValTyped(), qt.Equals, false) c.Assert(Item{Val: []byte("trues")}.ValTyped(), qt.Equals, "trues") - } diff --git a/parser/pageparser/pagelexer.go b/parser/pageparser/pagelexer.go index 7092b7b2b..c360642c4 100644 --- a/parser/pageparser/pagelexer.go +++ b/parser/pageparser/pagelexer.go @@ -59,7 +59,6 @@ func (l *pageLexer) Iterator() *Iterator { func (l *pageLexer) Input() []byte { return l.input - } type Config struct { @@ -286,7 +285,6 @@ func (s *sectionHandlers) skip() int { } func createSectionHandlers(l *pageLexer) *sectionHandlers { - shortCodeHandler := §ionHandler{ l: l, skipFunc: func(l *pageLexer) int { @@ -327,7 +325,6 @@ func createSectionHandlers(l *pageLexer) *sectionHandlers { skipFunc: func(l *pageLexer) int { if l.summaryDividerChecked || l.summaryDivider == nil { return -1 - } return l.index(l.summaryDivider) }, @@ -343,7 +340,6 @@ func createSectionHandlers(l *pageLexer) *sectionHandlers { l.emit(TypeLeadSummaryDivider) return origin, true - }, } @@ -425,7 +421,6 @@ func (s *sectionHandler) skip() int { } func lexMainSection(l *pageLexer) stateFunc { - if l.isEOF() { return lexDone } @@ -451,11 +446,9 @@ func lexMainSection(l *pageLexer) stateFunc { l.pos = len(l.input) return lexDone - } func lexDone(l *pageLexer) stateFunc { - // Done! if l.pos > l.start { l.emit(tText) diff --git a/parser/pageparser/pagelexer_intro.go b/parser/pageparser/pagelexer_intro.go index 45ad4f26a..961528ef2 100644 --- a/parser/pageparser/pagelexer_intro.go +++ b/parser/pageparser/pagelexer_intro.go @@ -147,12 +147,10 @@ LOOP: l.emit(TypeFrontMatterORG) return lexMainSection - } // Handle YAML or TOML front matter. func (l *pageLexer) lexFrontMatterSection(tp ItemType, delimr rune, name string, delim []byte) stateFunc { - for i := 0; i < 2; i++ { if r := l.next(); r != delimr { return l.errorf("invalid %s delimiter", name) diff --git a/parser/pageparser/pagelexer_shortcode.go b/parser/pageparser/pagelexer_shortcode.go index e8e3490aa..774a8f690 100644 --- a/parser/pageparser/pagelexer_shortcode.go +++ b/parser/pageparser/pagelexer_shortcode.go @@ -84,7 +84,6 @@ func lexShortcodeRightDelim(l *pageLexer) stateFunc { // 5. `param` // 6. param=`123` func lexShortcodeParam(l *pageLexer, escapedQuoteStart bool) stateFunc { - first := true nextEq := false @@ -138,7 +137,6 @@ func lexShortcodeParam(l *pageLexer, escapedQuoteStart bool) stateFunc { l.emit(tScParam) return lexInsideShortcode - } func lexShortcodeParamVal(l *pageLexer) stateFunc { @@ -356,7 +354,6 @@ func (l *pageLexer) currentLeftShortcodeDelim() []byte { return leftDelimScWithMarkup } return leftDelimScNoMarkup - } func (l *pageLexer) currentRightShortcodeDelim() []byte { diff --git a/parser/pageparser/pagelexer_test.go b/parser/pageparser/pagelexer_test.go index 3bc3bf6ad..00669c27b 100644 --- a/parser/pageparser/pagelexer_test.go +++ b/parser/pageparser/pagelexer_test.go @@ -25,5 +25,4 @@ func TestMinIndex(t *testing.T) { c.Assert(minIndex(4, 0, -2, 2, 5), qt.Equals, 0) c.Assert(minIndex(), qt.Equals, -1) c.Assert(minIndex(-2, -3), qt.Equals, -1) - } diff --git a/parser/pageparser/pageparser.go b/parser/pageparser/pageparser.go index 3d17aa8e0..19d068ece 100644 --- a/parser/pageparser/pageparser.go +++ b/parser/pageparser/pageparser.go @@ -71,7 +71,6 @@ func ParseFrontMatterAndContent(r io.Reader) (ContentFrontMatter, error) { frontMatterSource = item.Val } return true - } iter.PeekWalk(walkFn) diff --git a/parser/pageparser/pageparser_intro_test.go b/parser/pageparser/pageparser_intro_test.go index e776cb3ee..1b903d546 100644 --- a/parser/pageparser/pageparser_intro_test.go +++ b/parser/pageparser/pageparser_intro_test.go @@ -106,7 +106,6 @@ func collect(input []byte, skipFrontMatter bool, stateStart stateFunc) (items [] var cfg Config return collectWithConfig(input, skipFrontMatter, stateStart, cfg) - } // no positional checking, for now ... diff --git a/parser/pageparser/pageparser_main_test.go b/parser/pageparser/pageparser_main_test.go index 008c88c51..8fed2bffa 100644 --- a/parser/pageparser/pageparser_main_test.go +++ b/parser/pageparser/pageparser_main_test.go @@ -21,7 +21,7 @@ import ( func TestMain(t *testing.T) { t.Parallel() - var mainTests = []lexerTest{ + mainTests := []lexerTest{ {"emoji #1", "Some text with :emoji:", []Item{nti(tText, "Some text with "), nti(TypeEmoji, ":emoji:"), tstEOF}}, {"emoji #2", "Some text with :emoji: and some text.", []Item{nti(tText, "Some text with "), nti(TypeEmoji, ":emoji:"), nti(tText, " and some text."), tstEOF}}, {"looks like an emoji #1", "Some text and then :emoji", []Item{nti(tText, "Some text and then "), nti(tText, ":"), nti(tText, "emoji"), tstEOF}}, diff --git a/parser/pageparser/pageparser_shortcode_test.go b/parser/pageparser/pageparser_shortcode_test.go index b8bf5f727..54580217c 100644 --- a/parser/pageparser/pageparser_shortcode_test.go +++ b/parser/pageparser/pageparser_shortcode_test.go @@ -51,8 +51,10 @@ var shortCodeLexerTests = []lexerTest{ {"simple with markup", `{{% sc1 %}}`, []Item{tstLeftMD, tstSC1, tstRightMD, tstEOF}}, {"with spaces", `{{< sc1 >}}`, []Item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}}, - {"mismatched rightDelim", `{{< sc1 %}}`, []Item{tstLeftNoMD, tstSC1, - nti(tError, "unrecognized character in shortcode action: U+0025 '%'. Note: Parameters with non-alphanumeric args must be quoted")}}, + {"mismatched rightDelim", `{{< sc1 %}}`, []Item{ + 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{ tstLeftMD, tstSC1, @@ -65,57 +67,77 @@ var shortCodeLexerTests = []lexerTest{ tstEOF, }}, {"close, but no open", `{{< /sc1 >}}`, []Item{ - tstLeftNoMD, nti(tError, "got closing shortcode, but none is open")}}, + tstLeftNoMD, nti(tError, "got closing shortcode, but none is open"), + }}, {"close wrong", `{{< sc1 >}}{{< /another >}}`, []Item{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, - nti(tError, "closing tag for shortcode 'another' does not match start tag")}}, + nti(tError, "closing tag for shortcode 'another' does not match start tag"), + }}, {"close, but no open, more", `{{< sc1 >}}{{< /sc1 >}}{{< /another >}}`, []Item{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, - nti(tError, "closing tag for shortcode 'another' does not match start tag")}}, + nti(tError, "closing tag for shortcode 'another' does not match start tag"), + }}, {"close with extra keyword", `{{< sc1 >}}{{< /sc1 keyword>}}`, []Item{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1, - nti(tError, "unclosed shortcode")}}, + nti(tError, "unclosed shortcode"), + }}, {"float param, positional", `{{< sc1 3.14 >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "3.14"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "3.14"), tstRightNoMD, tstEOF, + }}, {"float param, named", `{{< sc1 param1=3.14 >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF, + }}, {"named param, raw string", `{{< sc1 param1=` + "`" + "Hello World" + "`" + " >}}", []Item{ - tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "Hello World"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "Hello World"), tstRightNoMD, tstEOF, + }}, {"float param, named, space before", `{{< sc1 param1= 3.14 >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF, + }}, {"Youtube id", `{{< sc1 -ziL-Q_456igdO-4 >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-Q_456igdO-4"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-Q_456igdO-4"), tstRightNoMD, tstEOF, + }}, {"non-alphanumerics param quoted", `{{< sc1 "-ziL-.%QigdO-4" >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-.%QigdO-4"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-.%QigdO-4"), tstRightNoMD, tstEOF, + }}, {"raw string", `{{< sc1` + "`" + "Hello World" + "`" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), tstRightNoMD, tstEOF, + }}, {"raw string with newline", `{{< sc1` + "`" + `Hello World` + "`" + ` >}}`, []Item{ tstLeftNoMD, tstSC1, nti(tScParam, `Hello - World`), tstRightNoMD, tstEOF}}, + World`), tstRightNoMD, tstEOF, + }}, {"raw string with escape character", `{{< sc1` + "`" + `Hello \b World` + "`" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, `Hello \b World`), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, `Hello \b World`), tstRightNoMD, tstEOF, + }}, {"two params", `{{< sc1 param1 param2 >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, tstParam2, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstParam2, tstRightNoMD, tstEOF, + }}, // issue #934 {"self-closing", `{{< sc1 />}}`, []Item{ - tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF, + }}, // Issue 2498 {"multiple self-closing", `{{< sc1 />}}{{< sc1 />}}`, []Item{ tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, - tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF, + }}, {"self-closing with param", `{{< sc1 param1 />}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF, + }}, {"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []Item{ tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, - tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF, + }}, {"multiple different self-closing with param", `{{< sc1 param1 />}}{{< sc2 param1 />}}`, []Item{ tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, - tstLeftNoMD, tstSC2, tstParam1, tstSCClose, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC2, tstParam1, tstSCClose, tstRightNoMD, tstEOF, + }}, {"nested simple", `{{< sc1 >}}{{< sc2 >}}{{< /sc1 >}}`, []Item{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSC2, tstRightNoMD, - tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstEOF, + }}, {"nested complex", `{{< sc1 >}}ab{{% sc2 param1 %}}cd{{< sc3 >}}ef{{< /sc3 >}}gh{{% /sc2 %}}ij{{< /sc1 >}}kl`, []Item{ tstLeftNoMD, tstSC1, tstRightNoMD, nti(tText, "ab"), @@ -132,64 +154,93 @@ var shortCodeLexerTests = []lexerTest{ }}, {"two quoted params", `{{< sc1 "param nr. 1" "param nr. 2" >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "param nr. 1"), nti(tScParam, "param nr. 2"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "param nr. 1"), nti(tScParam, "param nr. 2"), tstRightNoMD, tstEOF, + }}, {"two named params", `{{< sc1 param1="Hello World" param2="p2Val">}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, tstVal, tstParam2, nti(tScParamVal, "p2Val"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstVal, tstParam2, nti(tScParamVal, "p2Val"), tstRightNoMD, tstEOF, + }}, {"escaped quotes", `{{< sc1 param1=\"Hello World\" >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, tstVal, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstVal, tstRightNoMD, tstEOF, + }}, {"escaped quotes, positional param", `{{< sc1 \"param1\" >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, tstParam1, tstRightNoMD, tstEOF, + }}, {"escaped quotes inside escaped quotes", `{{< sc1 param1=\"Hello \"escaped\" World\" >}}`, []Item{ 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}}, - {"escaped quotes inside nonescaped quotes in positional param", - `{{< sc1 "Hello \"escaped\" World" >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF}}, + 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, + }, + }, + { + "escaped quotes inside nonescaped quotes in positional param", + `{{< sc1 "Hello \"escaped\" World" >}}`, + []Item{ + tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF, + }, + }, {"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character")}}, + tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"), + }}, {"escaped raw string, positional param", `{{< sc1 param1 ` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character")}}, + tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character"), + }}, {"two raw string params", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tScParam, "Second Param"), tstRightNoMD, tstEOF}}, + tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tScParam, "Second Param"), tstRightNoMD, tstEOF, + }}, {"unterminated quote", `{{< sc1 param2="Hello World>}}`, []Item{ - tstLeftNoMD, tstSC1, tstParam2, nti(tError, "unterminated quoted string in shortcode parameter-argument: 'Hello World>}}'")}}, + tstLeftNoMD, tstSC1, tstParam2, nti(tError, "unterminated quoted string in shortcode parameter-argument: 'Hello World>}}'"), + }}, {"unterminated raw string", `{{< sc1` + "`" + "Hello World" + ` >}}`, []Item{ - tstLeftNoMD, tstSC1, nti(tError, "unterminated raw string in shortcode parameter-argument: 'Hello World >}}'")}}, + 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{ - tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tError, "unterminated raw string in shortcode parameter-argument: 'Second Param >}}'")}}, + 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{ tstLeftNoMD, tstSC1, tstParam1, tstVal, - nti(tError, "got positional parameter 'p2'. Cannot mix named and positional parameters")}}, + 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{ tstLeftNoMD, tstSC1, tstParam1, tstVal, - nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters")}}, + 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{ tstLeftNoMD, tstSC1, tstParam1, tstVal, - nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters")}}, + 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{ tstLeftNoMD, tstSC1, tstParam1, - nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters")}}, + nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters"), + }}, {"ono positional param, one not", `{{< sc1 param1 param2="Hello World">}}`, []Item{ tstLeftNoMD, tstSC1, tstParam1, - nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters")}}, + nti(tError, "got named parameter 'param2'. Cannot mix named and positional parameters"), + }}, {"commented out", `{{</* sc1 */>}}`, []Item{ - nti(tText, "{{<"), nti(tText, " sc1 "), nti(tText, ">}}"), tstEOF}}, + nti(tText, "{{<"), nti(tText, " sc1 "), nti(tText, ">}}"), tstEOF, + }}, {"commented out, with asterisk inside", `{{</* sc1 "**/*.pdf" */>}}`, []Item{ - nti(tText, "{{<"), nti(tText, " sc1 \"**/*.pdf\" "), nti(tText, ">}}"), tstEOF}}, + nti(tText, "{{<"), nti(tText, " sc1 \"**/*.pdf\" "), nti(tText, ">}}"), tstEOF, + }}, {"commented out, missing close", `{{</* sc1 >}}`, []Item{ - nti(tError, "comment must be closed")}}, + nti(tError, "comment must be closed"), + }}, {"commented out, misplaced close", `{{</* sc1 >}}*/`, []Item{ - nti(tError, "comment must be closed")}}, + 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{ tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD, - tstLeftNoMD, tstSC2Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC2Inline, tstRightNoMD, tstEOF}}, + 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")}}, |