1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:28:58 +01:00
gojekyll/pages/drops_test.go
2021-06-16 14:51:59 +08:00

49 lines
1.4 KiB
Go

package pages
import (
"fmt"
"testing"
"time"
"github.com/osteele/gojekyll/config"
"github.com/osteele/liquid"
"github.com/osteele/liquid/tags"
"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)
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"])
}
func TestPage_ToLiquid_excerpt(t *testing.T) {
site := siteFake{t, config.Default()}
p, err := NewFile(site, "testdata/excerpt.md", "excerpt.md", map[string]interface{}{})
require.NoError(t, err)
t.Run("before render", func(t *testing.T) {
drop := p.(liquid.Drop).ToLiquid()
excerpt := drop.(tags.IterationKeyedMap)["excerpt"]
require.Equal(t, "First line.", fmt.Sprintf("%s", excerpt))
})
t.Run("after render", func(t *testing.T) {
require.NoError(t, p.(renderer).Render())
drop := p.(liquid.Drop).ToLiquid()
excerpt := drop.(tags.IterationKeyedMap)["excerpt"]
require.Equal(t, "rendered: First line.", fmt.Sprintf("%s", excerpt))
})
}
type renderer interface {
Render() error
}