mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 07:18:59 +01:00
30 lines
785 B
Go
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)
|
|
}
|