package lexers import ( "testing" assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" ) func TestGoHTMLTemplateIssue126(t *testing.T) { for _, source := range []string{ ` {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} {{ .Permalink }} Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }} Hugo -- gohugo.io{{ with .Site.LanguageCode }} {{.}}{{end}}{{ with .Site.Author.email }} {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} {{.}}{{end}}{{ if not .Date.IsZero }} {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} {{ with .OutputFormats.Get "RSS" }} {{ printf "" .Permalink .MediaType | safeHTML }} {{ end }} {{/* Print all pages */}} {{ range .Data.Pages }} {{ .Title }} {{ .Permalink }} {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} {{ .Permalink }} {{ .Summary | html }} {{ end }} `, `{{ $headless := .Site.GetPage "page" "some-headless-bundle" }} {{ $reusablePages := $headless.Resources.Match "author*" }}

Authors

{{ range $reusablePages }}

{{ .Title }}

{{ .Content }} {{ end }}`} { tokens, err := chroma.Tokenise(GoHTMLTemplate, nil, source) assert.NoError(t, err) assert.Equal(t, source, chroma.Stringify(tokens...)) } } func TestGoHTMLTemplateMultilineComments(t *testing.T) { for _, source := range []string{ ` {{/* This is a multiline comment */}} `, ` {{- /* This is a multiline comment */}} `, ` {{/* This is a multiline comment */ -}} `, ` {{- /* This is a multiline comment */ -}} `, } { tokens, err := chroma.Tokenise(GoHTMLTemplate, nil, source) assert.NoError(t, err) assert.Equal(t, source, chroma.Stringify(tokens...)) // Make sure that there are no errors for _, token := range tokens { assert.NotEqual(t, chroma.Error, token.Type) } // Make sure that multiline comments are printed found := false for _, token := range tokens { if token.Type == chroma.CommentMultiline { found = true } } assert.True(t, found) } } func TestGoHTMLTemplateNegativeNumber(t *testing.T) { for _, source := range []string{ ` {{ fn -3 }} `, } { tokens, err := chroma.Tokenise(GoHTMLTemplate, nil, source) assert.NoError(t, err) assert.Equal(t, source, chroma.Stringify(tokens...)) // Make sure that there are no errors for _, token := range tokens { assert.NotEqual(t, chroma.Error, token.Type) } // Make sure that negative number is found found := false for _, token := range tokens { if token.Type == chroma.LiteralNumberInteger { found = true } } assert.True(t, found) } }