mirror of
https://github.com/danog/gojekyll.git
synced 2025-01-22 21:51:37 +01:00
Each package has a test file
This commit is contained in:
parent
223ce39fe4
commit
ef85de3854
@ -100,6 +100,7 @@ make lint
|
||||
gojekyll render index.md # render a file to stdout
|
||||
gojekyll render / # render a URL to stdout
|
||||
gojekyll variables / # print a file or URL's variables
|
||||
./scripts/coverage && go tool cover -html=coverage.out
|
||||
```
|
||||
|
||||
`./scripts/gojekyll` is an alternative to the `gojekyll` executable, that uses `go run` each time it's invoked.
|
||||
|
@ -14,15 +14,14 @@ import (
|
||||
type Collection struct {
|
||||
Name string
|
||||
Metadata templates.VariableMap
|
||||
// context pages.Context
|
||||
pages []pages.Page
|
||||
pages []pages.Page
|
||||
}
|
||||
|
||||
// NewCollection creates a new Collection with metadata m
|
||||
func NewCollection(ctx pages.Context, name string, m templates.VariableMap) *Collection {
|
||||
// NewCollection creates a new Collection
|
||||
func NewCollection(ctx pages.Context, name string, metadata templates.VariableMap) *Collection {
|
||||
return &Collection{
|
||||
Name: name,
|
||||
Metadata: m,
|
||||
Metadata: metadata,
|
||||
}
|
||||
}
|
||||
|
||||
|
37
collections/collection_test.go
Normal file
37
collections/collection_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package collections
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/osteele/gojekyll/liquid"
|
||||
"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{}
|
||||
|
||||
func (c MockContext) FindLayout(_ string, _ *templates.VariableMap) (liquid.Template, error) {
|
||||
return nil, fmt.Errorf("unimplemented")
|
||||
}
|
||||
func (c MockContext) IsMarkdown(_ string) bool { return true }
|
||||
func (c MockContext) IsSassPath(_ string) bool { return true }
|
||||
func (c MockContext) SassIncludePaths() []string { return []string{} }
|
||||
func (c MockContext) SiteVariables() templates.VariableMap { return templates.VariableMap{} }
|
||||
func (c MockContext) SourceDir() string { return "." }
|
||||
func (c MockContext) TemplateEngine() liquid.Engine { return nil }
|
||||
func (c MockContext) WriteSass(io.Writer, []byte) error { return nil }
|
||||
|
||||
func TestCollections(t *testing.T) {
|
||||
ctx := MockContext{}
|
||||
c := NewCollection(ctx, "c", templates.VariableMap{"output": true})
|
||||
require.Equal(t, true, c.Output())
|
||||
require.Equal(t, "_c/", c.PathPrefix())
|
||||
}
|
21
config/config_test.go
Normal file
21
config/config_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
c := Default()
|
||||
require.Equal(t, ".", c.Source)
|
||||
require.Equal(t, "./_site", c.Destination)
|
||||
require.Equal(t, "_layouts", c.LayoutsDir)
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
c := Default()
|
||||
Unmarshal([]byte(`source: x`), &c)
|
||||
require.Equal(t, "x", c.Source)
|
||||
require.Equal(t, "./_site", c.Destination)
|
||||
}
|
@ -30,7 +30,7 @@ func (i TagInjector) Write(b []byte) (n int, err error) {
|
||||
return i.w.Write(b)
|
||||
}
|
||||
|
||||
// LiveReloadInjector returns a writer that injects the Live Reload JavaScript
|
||||
// NewLiveReloadInjector returns a writer that injects the Live Reload JavaScript
|
||||
// into its wrapped content.
|
||||
func NewLiveReloadInjector(w io.Writer) io.Writer {
|
||||
return TagInjector{w, liveReloadScriptTag}
|
||||
|
Loading…
x
Reference in New Issue
Block a user