2017-07-04 15:09:36 +02:00
|
|
|
package collection
|
2017-06-22 23:53:46 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-07-01 20:55:50 +02:00
|
|
|
"github.com/osteele/gojekyll/config"
|
2017-07-10 19:23:51 +02:00
|
|
|
"github.com/osteele/gojekyll/pipelines"
|
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-07-24 15:32:57 +02:00
|
|
|
func (s siteFake) Config() *config.Config { return &s.c }
|
|
|
|
func (s siteFake) Exclude(string) bool { return false }
|
|
|
|
func (s siteFake) OutputExt(string) string { return "" }
|
|
|
|
func (s siteFake) RelativePath(string) string { panic("unimplemented") }
|
|
|
|
func (s siteFake) RenderingPipeline() pipelines.PipelineInterface { panic("unimplemented") }
|
2017-06-24 17:05:57 +02:00
|
|
|
|
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-06-23 20:57:28 +02:00
|
|
|
require.Contains(t, c3.PermalinkPattern(), "/:year/:month/:day/:title")
|
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
|
|
|
}
|