Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/winter. a thoughtful static website generator for long-lasting content twos.dev/winter
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475package document // import "twos.dev/winter/document"
import ( "bytes" "fmt" "path/filepath" "strings" "testing"
"gotest.tools/v3/assert")
func surround(html string) string { return fmt.Sprintf("<html><head></head><body>%s</body></html>", html)}
func TestHTML(t *testing.T) { for _, test := range []testCase{ { name: "Heading", input: "<h1>Heading 1</h1><h2>Heading 2</h2>", expected: surround("<h2>Heading 2</h2>"), }, { name: "SimpleTemplate", input: `{{ add 1 2 }}`, expected: surround("{{ add 1 2 }}"), }, { name: "Template", input: `{{ template "_writing.html.tmpl" }}`, expected: surround("{{ template \"_writing.html.tmpl\" }}"), }, { name: "Image", input: `<img src="/path/to/image.jpg" alt="Alt text" />`, expected: surround("<img src=\"/path/to/image.jpg\" alt=\"Alt text\"/>"), }, } { t.Run(test.name, func(t *testing.T) { src := fmt.Sprintf("src/test/%s", test.name) doc := NewHTMLDocument( src, NewMetadata(src, filepath.Join("testdata", "templates")), nil, ) if err := doc.Load(strings.NewReader(test.input)); err != nil { assert.NilError(t, err) } var actual bytes.Buffer if err := doc.Render(&actual); err != nil { assert.NilError(t, err) } assert.Equal(t, test.expected, actual.String()) }) }}
func TestHTMLTitleWithInlineFormatting(t *testing.T) { src := "src/test/TitleWithInlineFormatting" doc := NewHTMLDocument( src, NewMetadata(src, filepath.Join("testdata", "templates")), nil, )
input := `<h1>What Makes <em>From</em> Soulslikes Different?</h1><p>Body</p>` assert.NilError(t, doc.Load(strings.NewReader(input))) assert.Equal(t, "What Makes From Soulslikes Different?", doc.Metadata().Title)
var actual bytes.Buffer assert.NilError(t, doc.Render(&actual)) assert.Equal(t, surround("<p>Body</p>"), actual.String())}