1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-04 17:27:51 +01:00
gojekyll/collections/collection_test.go

54 lines
1.6 KiB
Go
Raw Normal View History

2017-06-22 23:53:46 +02:00
package collections
import (
"path"
2017-06-22 23:53:46 +02:00
"testing"
"github.com/stretchr/testify/require"
)
var tests = []struct{ in, out string }{
{"pre</head>post", "pre:insertion:</head>post"},
{"pre:insertion:</head>post", "pre:insertion:</head>post"},
{"post", ":insertion:post"},
}
type MockContainer struct{}
2017-06-22 23:53:46 +02:00
func (c MockContainer) PathPrefix() string { return "" }
func (c MockContainer) OutputExt(filename string) string { return path.Ext(filename) }
2017-07-01 05:56:29 +02:00
// func (c MockPipeline) Render(_ io.Writer, _ []byte, _ string, _ map[string]interface{}) ([]byte, error) {
// return nil, fmt.Errorf("unimplemented")
// }
2017-07-01 05:56:29 +02:00
// func (c MockPipeline) ApplyLayout(_ string, _ []byte, _ map[string]interface{}) ([]byte, error) {
// return nil, fmt.Errorf("unimplemented")
// }
2017-07-01 05:56:29 +02:00
// func (c MockPipeline) SiteVariables() map[string]interface{} { return map[string]interface{}{} }
2017-06-22 23:53:46 +02:00
2017-06-23 20:57:28 +02:00
func TestNewCollection(t *testing.T) {
ctx := MockContainer{}
2017-06-23 20:57:28 +02:00
2017-07-01 05:56:29 +02:00
c1 := NewCollection("c", map[string]interface{}{"output": true}, ctx)
2017-06-23 20:57:28 +02:00
require.Equal(t, true, c1.Output())
require.Equal(t, "_c/", c1.PathPrefix())
2017-07-01 05:56:29 +02:00
c2 := NewCollection("c", map[string]interface{}{}, ctx)
2017-06-23 20:57:28 +02:00
require.Equal(t, false, c2.Output())
}
func TestPermalinkPattern(t *testing.T) {
ctx := MockContainer{}
2017-06-23 20:57:28 +02:00
2017-07-01 05:56:29 +02:00
c1 := NewCollection("c", map[string]interface{}{}, ctx)
2017-06-23 20:57:28 +02:00
require.Contains(t, c1.PermalinkPattern(), ":collection")
2017-07-01 05:56:29 +02:00
c2 := NewCollection("c", map[string]interface{}{"permalink": "out"}, ctx)
2017-06-23 20:57:28 +02:00
require.Equal(t, "out", c2.PermalinkPattern())
2017-07-01 05:56:29 +02:00
c3 := NewCollection("posts", map[string]interface{}{}, ctx)
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
}