2017-06-22 23:53:46 +02:00
|
|
|
package collections
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-06-24 17:05:57 +02:00
|
|
|
"path"
|
2017-06-22 23:53:46 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/osteele/gojekyll/templates"
|
|
|
|
"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 MockContext struct{}
|
|
|
|
|
2017-06-24 17:05:57 +02:00
|
|
|
func (c MockContext) OutputExt(filename string) string {
|
|
|
|
return path.Ext(filename)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c MockContext) Render(_ io.Writer, _ []byte, _ string, _ templates.VariableMap) ([]byte, error) {
|
|
|
|
return nil, fmt.Errorf("unimplemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c MockContext) ApplyLayout(_ string, _ []byte, _ templates.VariableMap) ([]byte, error) {
|
2017-06-22 23:53:46 +02:00
|
|
|
return nil, fmt.Errorf("unimplemented")
|
|
|
|
}
|
2017-06-24 17:05:57 +02:00
|
|
|
|
2017-06-22 23:53:46 +02:00
|
|
|
func (c MockContext) SiteVariables() templates.VariableMap { return templates.VariableMap{} }
|
|
|
|
|
2017-06-23 20:57:28 +02:00
|
|
|
func TestNewCollection(t *testing.T) {
|
2017-06-22 23:53:46 +02:00
|
|
|
ctx := MockContext{}
|
2017-06-23 20:57:28 +02:00
|
|
|
|
|
|
|
c1 := NewCollection(ctx, "c", templates.VariableMap{"output": true})
|
|
|
|
require.Equal(t, true, c1.Output())
|
|
|
|
require.Equal(t, "_c/", c1.PathPrefix())
|
|
|
|
|
|
|
|
c2 := NewCollection(ctx, "c", templates.VariableMap{})
|
|
|
|
require.Equal(t, false, c2.Output())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPermalinkPattern(t *testing.T) {
|
|
|
|
ctx := MockContext{}
|
|
|
|
|
|
|
|
c1 := NewCollection(ctx, "c", templates.VariableMap{})
|
|
|
|
require.Contains(t, c1.PermalinkPattern(), ":collection")
|
|
|
|
|
|
|
|
c2 := NewCollection(ctx, "c", templates.VariableMap{"permalink": "out"})
|
|
|
|
require.Equal(t, "out", c2.PermalinkPattern())
|
|
|
|
|
|
|
|
c3 := NewCollection(ctx, "posts", templates.VariableMap{})
|
|
|
|
require.Contains(t, c3.PermalinkPattern(), "/:year/:month/:day/:title")
|
2017-06-22 23:53:46 +02:00
|
|
|
}
|