hugoblib: Clean up the time tests

This commit is contained in:
Bjørn Erik Pedersen 2016-03-24 13:30:08 +01:00
parent 944090722e
commit e467d23374

View file

@ -21,73 +21,75 @@ import (
"time" "time"
) )
var PAGE_WITH_INVALID_DATE = `--- const (
pageWithInvalidDate = `---
date: 2010-05-02_15:29:31+08:00 date: 2010-05-02_15:29:31+08:00
--- ---
Page With Invalid Date (replace T with _ for RFC 3339)` Page With Invalid Date (replace T with _ for RFC 3339)`
var PAGE_WITH_DATE_RFC3339 = `--- pageWithDateRFC3339 = `---
date: 2010-05-02T15:29:31+08:00 date: 2010-05-02T15:29:31+08:00
--- ---
Page With Date RFC3339` Page With Date RFC3339`
var PAGE_WITH_DATE_RFC3339_NO_T = `--- pageWithDateRFC3339NoT = `---
date: 2010-05-02 15:29:31+08:00 date: 2010-05-02 15:29:31+08:00
--- ---
Page With Date RFC3339_NO_T` Page With Date RFC3339_NO_T`
var PAGE_WITH_DATE_RFC1123 = `--- pageWithRFC1123 = `---
date: Sun, 02 May 2010 15:29:31 PST date: Sun, 02 May 2010 15:29:31 PST
--- ---
Page With Date RFC1123` Page With Date RFC1123`
var PAGE_WITH_DATE_RFC1123Z = `--- pageWithDateRFC1123Z = `---
date: Sun, 02 May 2010 15:29:31 +0800 date: Sun, 02 May 2010 15:29:31 +0800
--- ---
Page With Date RFC1123Z` Page With Date RFC1123Z`
var PAGE_WITH_DATE_RFC822 = `--- pageWithDateRFC822 = `---
date: 02 May 10 15:29 PST date: 02 May 10 15:29 PST
--- ---
Page With Date RFC822` Page With Date RFC822`
var PAGE_WITH_DATE_RFC822Z = `--- pageWithDateRFC822Z = `---
date: 02 May 10 15:29 +0800 date: 02 May 10 15:29 +0800
--- ---
Page With Date RFC822Z` Page With Date RFC822Z`
var PAGE_WITH_DATE_ANSIC = `--- pageWithDateANSIC = `---
date: Sun May 2 15:29:31 2010 date: Sun May 2 15:29:31 2010
--- ---
Page With Date ANSIC` Page With Date ANSIC`
var PAGE_WITH_DATE_UnixDate = `--- pageWithDateUnixDate = `---
date: Sun May 2 15:29:31 PST 2010 date: Sun May 2 15:29:31 PST 2010
--- ---
Page With Date UnixDate` Page With Date UnixDate`
var PAGE_WITH_DATE_RubyDate = `--- pageWithDateRubyDate = `---
date: Sun May 02 15:29:31 +0800 2010 date: Sun May 02 15:29:31 +0800 2010
--- ---
Page With Date RubyDate` Page With Date RubyDate`
var PAGE_WITH_DATE_HugoYearNumeric = `--- pageWithDateHugoYearNumeric = `---
date: 2010-05-02 date: 2010-05-02
--- ---
Page With Date HugoYearNumeric` Page With Date HugoYearNumeric`
var PAGE_WITH_DATE_HugoYear = `--- pageWithDateHugoYear = `---
date: 02 May 2010 date: 02 May 2010
--- ---
Page With Date HugoYear` Page With Date HugoYear`
var PAGE_WITH_DATE_HugoLong = `--- pageWithDateHugoLong = `---
date: 02 May 2010 15:29 PST date: 02 May 2010 15:29 PST
--- ---
Page With Date HugoLong` Page With Date HugoLong`
)
func TestDegenerateDateFrontMatter(t *testing.T) { func TestDegenerateDateFrontMatter(t *testing.T) {
p, _ := NewPageFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date") p, _ := NewPageFrom(strings.NewReader(pageWithInvalidDate), "page/with/invalid/date")
if p.Date != *new(time.Time) { if p.Date != *new(time.Time) {
t.Fatalf("Date should be set to time.Time zero value. Got: %s", p.Date) t.Fatalf("Date should be set to time.Time zero value. Got: %s", p.Date)
} }
@ -98,24 +100,24 @@ func TestParsingDateInFrontMatter(t *testing.T) {
buf string buf string
dt string dt string
}{ }{
{PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"}, {pageWithDateRFC3339, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC3339_NO_T, "2010-05-02T15:29:31+08:00"}, {pageWithDateRFC3339NoT, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC1123Z, "2010-05-02T15:29:31+08:00"}, {pageWithDateRFC1123Z, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+08:00"}, {pageWithDateRFC822Z, "2010-05-02T15:29:00+08:00"},
{PAGE_WITH_DATE_ANSIC, "2010-05-02T15:29:31Z"}, {pageWithDateANSIC, "2010-05-02T15:29:31Z"},
{PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"}, {pageWithDateRubyDate, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_HugoYearNumeric, "2010-05-02T00:00:00Z"}, {pageWithDateHugoYearNumeric, "2010-05-02T00:00:00Z"},
{PAGE_WITH_DATE_HugoYear, "2010-05-02T00:00:00Z"}, {pageWithDateHugoYear, "2010-05-02T00:00:00Z"},
} }
tzShortCodeTests := []struct { tzShortCodeTests := []struct {
buf string buf string
dt string dt string
}{ }{
{PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"}, {pageWithRFC1123, "2010-05-02T15:29:31-08:00"},
{PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00Z"}, {pageWithDateRFC822, "2010-05-02T15:29:00-08:00Z"},
{PAGE_WITH_DATE_UnixDate, "2010-05-02T15:29:31-08:00"}, {pageWithDateUnixDate, "2010-05-02T15:29:31-08:00"},
{PAGE_WITH_DATE_HugoLong, "2010-05-02T15:21:00+08:00"}, {pageWithDateHugoLong, "2010-05-02T15:21:00+08:00"},
} }
if _, err := time.LoadLocation("PST"); err == nil { if _, err := time.LoadLocation("PST"); err == nil {