1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 15:47:47 +01:00
gojekyll/pages/drops_test.go

49 lines
1.4 KiB
Go
Raw Normal View History

2017-07-07 01:31:36 +02:00
package pages
import (
2017-08-10 16:44:04 +02:00
"fmt"
2017-07-07 01:31:36 +02:00
"testing"
"time"
2017-07-07 01:31:36 +02:00
"github.com/osteele/gojekyll/config"
2017-07-09 01:57:41 +02:00
"github.com/osteele/liquid"
2017-08-16 00:55:18 +02:00
"github.com/osteele/liquid/tags"
2017-07-07 01:31:36 +02:00
"github.com/stretchr/testify/require"
)
func TestStaticFile_ToLiquid(t *testing.T) {
site := siteFake{t, config.Default()}
page, err := NewFile(site, "testdata/static.html", "static.html", map[string]interface{}{})
require.NoError(t, err)
2017-08-16 00:55:18 +02:00
drop := page.(liquid.Drop).ToLiquid().(tags.IterationKeyedMap)
require.Equal(t, "static", drop["basename"])
require.Equal(t, "static.html", drop["name"])
require.Equal(t, "/static.html", drop["path"])
require.Equal(t, ".html", drop["extname"])
require.IsType(t, time.Now(), drop["modified_time"])
}
2017-08-10 16:44:04 +02:00
func TestPage_ToLiquid_excerpt(t *testing.T) {
site := siteFake{t, config.Default()}
2017-08-10 15:06:53 +02:00
p, err := NewFile(site, "testdata/excerpt.md", "excerpt.md", map[string]interface{}{})
2017-07-07 01:31:36 +02:00
require.NoError(t, err)
2017-08-10 16:44:04 +02:00
t.Run("before render", func(t *testing.T) {
drop := p.(liquid.Drop).ToLiquid()
2017-08-16 00:55:18 +02:00
excerpt := drop.(tags.IterationKeyedMap)["excerpt"]
require.Equal(t, "First line.", fmt.Sprintf("%s", excerpt))
})
2017-08-10 16:44:04 +02:00
t.Run("after render", func(t *testing.T) {
2017-09-03 18:18:17 +02:00
require.NoError(t, p.(renderer).Render())
drop := p.(liquid.Drop).ToLiquid()
2017-08-16 00:55:18 +02:00
excerpt := drop.(tags.IterationKeyedMap)["excerpt"]
require.Equal(t, "rendered: First line.", fmt.Sprintf("%s", excerpt))
})
2017-07-07 01:31:36 +02:00
}
2017-09-03 18:18:17 +02:00
type renderer interface {
Render() error
}