1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 06:39:03 +01:00
gojekyll/collection/collection_test.go

64 lines
2.0 KiB
Go
Raw Normal View History

2017-07-04 15:09:36 +02:00
package collection
2017-06-22 23:53:46 +02:00
import (
"testing"
"github.com/danog/gojekyll/config"
"github.com/danog/gojekyll/renderers"
2017-06-22 23:53:46 +02:00
"github.com/stretchr/testify/require"
)
2017-07-24 15:32:57 +02:00
type siteFake struct{ c config.Config }
2017-06-22 23:53:46 +02:00
2017-08-18 17:07:01 +02:00
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) Exclude(string) bool { return false }
func (s siteFake) RelativePath(string) string { panic("unimplemented") }
func (s siteFake) RendererManager() renderers.Renderers { panic("unimplemented") }
2017-06-23 20:57:28 +02:00
func TestNewCollection(t *testing.T) {
2017-07-24 15:32:57 +02:00
site := siteFake{config.Default()}
2017-06-23 20:57:28 +02:00
2017-07-04 15:09:36 +02:00
c1 := New(site, "c", map[string]interface{}{"output": true})
2017-06-23 20:57:28 +02:00
require.Equal(t, true, c1.Output())
require.Equal(t, "_c/", c1.PathPrefix())
2017-07-04 15:09:36 +02:00
c2 := New(site, "c", map[string]interface{}{})
2017-06-23 20:57:28 +02:00
require.Equal(t, false, c2.Output())
}
func TestPermalinkPattern(t *testing.T) {
2017-07-24 15:32:57 +02:00
site := siteFake{config.Default()}
2017-06-23 20:57:28 +02:00
2017-07-04 15:09:36 +02:00
c1 := New(site, "c", map[string]interface{}{})
2017-06-23 20:57:28 +02:00
require.Contains(t, c1.PermalinkPattern(), ":collection")
2017-07-04 15:09:36 +02:00
c2 := New(site, "c", map[string]interface{}{"permalink": "out"})
2017-06-23 20:57:28 +02:00
require.Equal(t, "out", c2.PermalinkPattern())
2017-07-04 15:09:36 +02:00
c3 := New(site, "posts", map[string]interface{}{})
2017-08-27 20:18:57 +02:00
require.Contains(t, c3.PermalinkPattern(), "date")
2017-06-22 23:53:46 +02:00
}
2017-07-03 17:48:06 +02:00
2017-08-10 16:51:29 +02:00
func Test_ReadPages(t *testing.T) {
2017-07-24 15:32:57 +02:00
site := siteFake{config.FromString("source: testdata")}
2017-07-04 15:09:36 +02:00
c := New(site, "posts", map[string]interface{}{})
2017-07-03 19:03:45 +02:00
require.NoError(t, c.ReadPages())
2017-07-03 17:48:06 +02:00
require.Len(t, c.Pages(), 1)
2017-07-24 15:32:57 +02:00
site = siteFake{config.FromString("source: testdata\nunpublished: true")}
2017-07-04 15:09:36 +02:00
c = New(site, "posts", map[string]interface{}{})
2017-07-03 19:03:45 +02:00
require.NoError(t, c.ReadPages())
2017-07-03 17:48:06 +02:00
require.Len(t, c.Pages(), 2)
2017-07-24 15:32:57 +02:00
site = siteFake{config.FromString("source: testdata\nfuture: true")}
2017-07-04 15:09:36 +02:00
c = New(site, "posts", map[string]interface{}{})
2017-07-03 19:03:45 +02:00
require.NoError(t, c.ReadPages())
2017-07-03 17:48:06 +02:00
require.Len(t, c.Pages(), 2)
2017-08-10 16:51:29 +02:00
pages := c.Pages()
require.Equal(t, nil, pages[0].FrontMatter()["previous"])
require.Equal(t, pages[1], pages[0].FrontMatter()["next"])
require.Equal(t, pages[0], pages[1].FrontMatter()["previous"])
require.Equal(t, nil, pages[1].FrontMatter()["next"])
2017-07-03 17:48:06 +02:00
}