mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -49,6 +49,7 @@ func preparePageGroupTestPages(t *testing.T) Pages {
|
||||
p.date = cast.ToTime(src.date)
|
||||
p.pubDate = cast.ToTime(src.date)
|
||||
p.expiryDate = cast.ToTime(src.date)
|
||||
p.lastMod = cast.ToTime(src.date).AddDate(3, 0, 0)
|
||||
p.params["custom_param"] = src.param
|
||||
p.params["custom_date"] = cast.ToTime(src.date)
|
||||
pages = append(pages, p)
|
||||
@@ -378,6 +379,42 @@ func TestGroupByParamDate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupByLastmod(t *testing.T) {
|
||||
t.Parallel()
|
||||
pages := preparePageGroupTestPages(t)
|
||||
expect := PagesGroup{
|
||||
{Key: "2015-04", Pages: Pages{pages[4], pages[2], pages[0]}},
|
||||
{Key: "2015-03", Pages: Pages{pages[3]}},
|
||||
{Key: "2015-01", Pages: Pages{pages[1]}},
|
||||
}
|
||||
|
||||
groups, err := pages.GroupByLastmod("2006-01")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to make PagesGroup array: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(groups, expect) {
|
||||
t.Errorf("PagesGroup has unexpected groups. It should be %#v, got %#v", expect, groups)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupByLastmodInReverseOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
pages := preparePageGroupTestPages(t)
|
||||
expect := PagesGroup{
|
||||
{Key: "2015-01", Pages: Pages{pages[1]}},
|
||||
{Key: "2015-03", Pages: Pages{pages[3]}},
|
||||
{Key: "2015-04", Pages: Pages{pages[0], pages[2], pages[4]}},
|
||||
}
|
||||
|
||||
groups, err := pages.GroupByLastmod("2006-01", "asc")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to make PagesGroup array: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(groups, expect) {
|
||||
t.Errorf("PagesGroup has unexpected groups. It should be\n%#v, got\n%#v", expect, groups)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupByParamDateInReverseOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
pages := preparePageGroupTestPages(t)
|
||||
|
Reference in New Issue
Block a user