1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:19:00 +01:00
gojekyll/utils/filepath_test.go
2017-08-20 12:56:23 -04:00

45 lines
1007 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, title, found := FilenameDate("2017-07-02-post.html")
require.True(t, found)
require.Equal(t, "post", title)
require.Equal(t, timeMustParse("2017-07-02T00:00:00-04:00"), 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("/"))
}