1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:28:58 +01:00
gojekyll/utils/filepath_test.go
2017-08-20 13:34:47 -04:00

47 lines
1.1 KiB
Go

package utils
import (
"os"
"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 TestParseFilenameDate(t *testing.T) {
os.Setenv("TZ", "America/New_York") // nolint: errcheck
d, title, found := ParseFilenameDateTitle("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 = ParseFilenameDateTitle("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("/"))
}