mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-26 06:31:29 +00:00
hugoblib: Clean up the time tests
This commit is contained in:
parent
944090722e
commit
e467d23374
1 changed files with 28 additions and 26 deletions
|
@ -21,73 +21,75 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var PAGE_WITH_INVALID_DATE = `---
|
||||
const (
|
||||
pageWithInvalidDate = `---
|
||||
date: 2010-05-02_15:29:31+08:00
|
||||
---
|
||||
Page With Invalid Date (replace T with _ for RFC 3339)`
|
||||
|
||||
var PAGE_WITH_DATE_RFC3339 = `---
|
||||
pageWithDateRFC3339 = `---
|
||||
date: 2010-05-02T15:29:31+08:00
|
||||
---
|
||||
Page With Date RFC3339`
|
||||
|
||||
var PAGE_WITH_DATE_RFC3339_NO_T = `---
|
||||
pageWithDateRFC3339NoT = `---
|
||||
date: 2010-05-02 15:29:31+08:00
|
||||
---
|
||||
Page With Date RFC3339_NO_T`
|
||||
|
||||
var PAGE_WITH_DATE_RFC1123 = `---
|
||||
pageWithRFC1123 = `---
|
||||
date: Sun, 02 May 2010 15:29:31 PST
|
||||
---
|
||||
Page With Date RFC1123`
|
||||
|
||||
var PAGE_WITH_DATE_RFC1123Z = `---
|
||||
pageWithDateRFC1123Z = `---
|
||||
date: Sun, 02 May 2010 15:29:31 +0800
|
||||
---
|
||||
Page With Date RFC1123Z`
|
||||
|
||||
var PAGE_WITH_DATE_RFC822 = `---
|
||||
pageWithDateRFC822 = `---
|
||||
date: 02 May 10 15:29 PST
|
||||
---
|
||||
Page With Date RFC822`
|
||||
|
||||
var PAGE_WITH_DATE_RFC822Z = `---
|
||||
pageWithDateRFC822Z = `---
|
||||
date: 02 May 10 15:29 +0800
|
||||
---
|
||||
Page With Date RFC822Z`
|
||||
|
||||
var PAGE_WITH_DATE_ANSIC = `---
|
||||
pageWithDateANSIC = `---
|
||||
date: Sun May 2 15:29:31 2010
|
||||
---
|
||||
Page With Date ANSIC`
|
||||
|
||||
var PAGE_WITH_DATE_UnixDate = `---
|
||||
pageWithDateUnixDate = `---
|
||||
date: Sun May 2 15:29:31 PST 2010
|
||||
---
|
||||
Page With Date UnixDate`
|
||||
|
||||
var PAGE_WITH_DATE_RubyDate = `---
|
||||
pageWithDateRubyDate = `---
|
||||
date: Sun May 02 15:29:31 +0800 2010
|
||||
---
|
||||
Page With Date RubyDate`
|
||||
|
||||
var PAGE_WITH_DATE_HugoYearNumeric = `---
|
||||
pageWithDateHugoYearNumeric = `---
|
||||
date: 2010-05-02
|
||||
---
|
||||
Page With Date HugoYearNumeric`
|
||||
|
||||
var PAGE_WITH_DATE_HugoYear = `---
|
||||
pageWithDateHugoYear = `---
|
||||
date: 02 May 2010
|
||||
---
|
||||
Page With Date HugoYear`
|
||||
|
||||
var PAGE_WITH_DATE_HugoLong = `---
|
||||
pageWithDateHugoLong = `---
|
||||
date: 02 May 2010 15:29 PST
|
||||
---
|
||||
Page With Date HugoLong`
|
||||
)
|
||||
|
||||
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) {
|
||||
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
|
||||
dt string
|
||||
}{
|
||||
{PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"},
|
||||
{PAGE_WITH_DATE_RFC3339_NO_T, "2010-05-02T15:29:31+08:00"},
|
||||
{PAGE_WITH_DATE_RFC1123Z, "2010-05-02T15:29:31+08:00"},
|
||||
{PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+08:00"},
|
||||
{PAGE_WITH_DATE_ANSIC, "2010-05-02T15:29:31Z"},
|
||||
{PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"},
|
||||
{PAGE_WITH_DATE_HugoYearNumeric, "2010-05-02T00:00:00Z"},
|
||||
{PAGE_WITH_DATE_HugoYear, "2010-05-02T00:00:00Z"},
|
||||
{pageWithDateRFC3339, "2010-05-02T15:29:31+08:00"},
|
||||
{pageWithDateRFC3339NoT, "2010-05-02T15:29:31+08:00"},
|
||||
{pageWithDateRFC1123Z, "2010-05-02T15:29:31+08:00"},
|
||||
{pageWithDateRFC822Z, "2010-05-02T15:29:00+08:00"},
|
||||
{pageWithDateANSIC, "2010-05-02T15:29:31Z"},
|
||||
{pageWithDateRubyDate, "2010-05-02T15:29:31+08:00"},
|
||||
{pageWithDateHugoYearNumeric, "2010-05-02T00:00:00Z"},
|
||||
{pageWithDateHugoYear, "2010-05-02T00:00:00Z"},
|
||||
}
|
||||
|
||||
tzShortCodeTests := []struct {
|
||||
buf string
|
||||
dt string
|
||||
}{
|
||||
{PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"},
|
||||
{PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00Z"},
|
||||
{PAGE_WITH_DATE_UnixDate, "2010-05-02T15:29:31-08:00"},
|
||||
{PAGE_WITH_DATE_HugoLong, "2010-05-02T15:21:00+08:00"},
|
||||
{pageWithRFC1123, "2010-05-02T15:29:31-08:00"},
|
||||
{pageWithDateRFC822, "2010-05-02T15:29:00-08:00Z"},
|
||||
{pageWithDateUnixDate, "2010-05-02T15:29:31-08:00"},
|
||||
{pageWithDateHugoLong, "2010-05-02T15:21:00+08:00"},
|
||||
}
|
||||
|
||||
if _, err := time.LoadLocation("PST"); err == nil {
|
||||
|
|
Loading…
Reference in a new issue