2017-06-22 23:53:46 +02:00
|
|
|
package collections
|
|
|
|
|
|
|
|
import (
|
2017-06-24 17:05:57 +02:00
|
|
|
"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"},
|
|
|
|
}
|
|
|
|
|
2017-06-24 18:03:33 +02:00
|
|
|
type MockContainer struct{}
|
2017-06-22 23:53:46 +02:00
|
|
|
|
2017-06-24 18:03:33 +02:00
|
|
|
func (c MockContainer) PathPrefix() string { return "" }
|
|
|
|
func (c MockContainer) OutputExt(filename string) string { return path.Ext(filename) }
|
2017-06-24 17:05:57 +02:00
|
|
|
|
2017-07-01 05:56:29 +02:00
|
|
|
// func (c MockPipeline) Render(_ io.Writer, _ []byte, _ string, _ map[string]interface{}) ([]byte, error) {
|
2017-06-24 18:03:33 +02:00
|
|
|
// return nil, fmt.Errorf("unimplemented")
|
|
|
|
// }
|
2017-06-24 17:05:57 +02:00
|
|
|
|
2017-07-01 05:56:29 +02:00
|
|
|
// func (c MockPipeline) ApplyLayout(_ string, _ []byte, _ map[string]interface{}) ([]byte, error) {
|
2017-06-24 18:03:33 +02:00
|
|
|
// return nil, fmt.Errorf("unimplemented")
|
|
|
|
// }
|
2017-06-24 17:05:57 +02:00
|
|
|
|
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) {
|
2017-06-24 18:03:33 +02:00
|
|
|
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) {
|
2017-06-24 18:03:33 +02:00
|
|
|
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
|
|
|
}
|