1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 08:44:41 +01:00
gojekyll/utils/filepath_test.go
2017-07-14 11:41:28 -04:00

44 lines
959 B
Go

package utils
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func timeMustParse(s string) time.Time {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
panic(err)
}
return t
}
func TestMustAbs(t *testing.T) {
require.True(t, strings.HasPrefix(MustAbs("."), "/"))
}
func TestFilenameDate(t *testing.T) {
d, found := FilenameDate("2017-07-02-post.html")
require.True(t, found)
require.Equal(t, timeMustParse("2017-07-02T00:00:00Z"), d)
_, found = FilenameDate("not-post.html")
require.False(t, found)
}
func TestTrimExt(t *testing.T) {
require.Equal(t, "/a/b", TrimExt("/a/b.c"))
require.Equal(t, "/a/b", TrimExt("/a/b"))
}
func TestURLPathClean(t *testing.T) {
require.Equal(t, "/a/b", URLPathClean("/a/b"))
require.Equal(t, "/a/b/", URLPathClean("/a/b/"))
require.Equal(t, "/a/b", URLPathClean("/a//b"))
require.Equal(t, "/b", URLPathClean("/a/../b"))
require.Equal(t, "/", URLPathClean("/"))
}