github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/render/markdown_test.go (about) 1 package render 2 3 import ( 4 "bytes" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 const mdTemplate = "my-template.md" 12 13 func Test_MD_WithoutLayout(t *testing.T) { 14 r := require.New(t) 15 16 e := NewEngine() 17 18 box := e.TemplatesBox 19 r.NoError(box.AddString(mdTemplate, "<%= name %>")) 20 21 h := e.HTML(mdTemplate) 22 r.Equal("text/html; charset=utf-8", h.ContentType()) 23 bb := &bytes.Buffer{} 24 25 r.NoError(h.Render(bb, Data{"name": "Mark"})) 26 r.Equal("<p>Mark</p>", strings.TrimSpace(bb.String())) 27 } 28 29 func Test_MD_WithLayout(t *testing.T) { 30 r := require.New(t) 31 32 e := NewEngine() 33 e.HTMLLayout = htmlLayout 34 35 box := e.TemplatesBox 36 r.NoError(box.AddString(mdTemplate, "<%= name %>")) 37 r.NoError(box.AddString(htmlLayout, "<body><%= yield %></body>")) 38 39 h := e.HTML(mdTemplate) 40 r.Equal("text/html; charset=utf-8", h.ContentType()) 41 bb := &bytes.Buffer{} 42 43 r.NoError(h.Render(bb, Data{"name": "Mark"})) 44 r.Equal("<body><p>Mark</p>\n</body>", strings.TrimSpace(bb.String())) 45 }