1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 23:24:39 +01:00
gojekyll/frontmatter/frontmatter_test.go
2017-09-02 14:09:04 -04:00

30 lines
785 B
Go

package frontmatter
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFileHasFrontMatter(t *testing.T) {
fm := func(filename string) bool {
fm, err := FileHasFrontMatter(filename)
require.NoError(t, err)
return fm
}
require.True(t, fm("testdata/empty_fm.md"))
require.True(t, fm("testdata/some_fm.md"))
require.False(t, fm("testdata/no_fm.md"))
}
func TestFrontMatter_SortedStringArray(t *testing.T) {
sorted := func(v interface{}) []string {
fm := FrontMatter{"categories": v}
return fm.SortedStringArray("categories")
}
require.Equal(t, []string{"a", "b"}, sorted("b a"))
require.Equal(t, []string{"a", "b"}, sorted([]interface{}{"b", "a"}))
require.Equal(t, []string{"a", "b"}, sorted([]string{"b", "a"}))
require.Len(t, sorted(3), 0)
}