package 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("%s", html) } func TestHTML(t *testing.T) { for _, test := range []testCase{ { name: "Heading", input: "

Heading 1

Heading 2

", expected: surround("

Heading 2

"), }, { 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: `Alt text`, expected: surround("\"Alt"), }, } { 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 := `

What Makes From Soulslikes Different?

Body

` 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("

Body

"), actual.String()) }