1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 11:34:46 +01:00
gojekyll/utils/filepath_test.go

44 lines
959 B
Go
Raw Normal View History

2017-07-09 22:17:20 +02:00
package utils
import (
2017-07-03 17:48:06 +02:00
"strings"
"testing"
2017-07-03 16:39:55 +02:00
"time"
"github.com/stretchr/testify/require"
)
2017-07-03 16:39:55 +02:00
func timeMustParse(s string) time.Time {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
panic(err)
}
return t
}
2017-07-03 17:48:06 +02:00
func TestMustAbs(t *testing.T) {
require.True(t, strings.HasPrefix(MustAbs("."), "/"))
}
2017-07-03 16:39:55 +02:00
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)
2017-07-03 19:03:45 +02:00
_, found = FilenameDate("not-post.html")
2017-07-03 16:39:55 +02:00
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("/"))
}